šŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #148

Re: ROUND function

#148
From: dxf
Date: Tue, 20 Oct 2026 13:50
29 lines
1688 bytes
On 19/10/2026 12:29 pm, dxf wrote:
> On 19/10/2026 3:47 am, marcel hendrix wrote:
>> On 10/18/2026 6:09 PM, dxf wrote:
>>
>>> It appears ROUND() is a fairly common function.Ā  I created it using
>>> a factor from REPRESENT.Ā  Are there other ways implementing it?
>>>
>>>
>>> \ SCALE ( r1 n -- r2 )Ā  scale r1 left/right by n digits
>>>
>>> : ROUND ( r1 n -- r2 )
>>> Ā Ā  >rĀ  fbad? ifĀ  2dropĀ  rdropĀ  end
>>> Ā Ā  r@ scaleĀ  froundĀ  r> negate scale ;
>> [..]
>>
>> Interesting. Please show your current SCALE and fbad? words.
>> -marcel
> 
> https://pastebin.com/skQArj3E
> 
> (If F^N looks familiar, I adapted it from JVN's dd^n )

BTW for this use SCALE can be simplified to:

  : SCALE ( r1 n -- r2 )  >r f10. r> f^n f* ;

as only numbers with powers <= precision would be involved.
In REPRESENT SCALE had to deal multipliers exceeding 10^308.
Technical Details
Message-ID: <6ad771ad$1@news.ausics.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.ausics.net!not-for-mail
References: <6ad4ef23$1@news.ausics.net> <11b2t7k$229ps$1@dont-email.me> <6ad57278$1@news.ausics.net>

Show Full Headers
Complete Article Headers
Date: Wed, 21 Oct 2026 00:50:37 +1100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: ROUND function
Newsgroups: comp.lang.forth
References: <6ad4ef23$1@news.ausics.net> <11b2t7k$229ps$1@dont-email.me>
 <6ad57278$1@news.ausics.net>
Content-Language: en-GB
From: dxf <dxforth@gmail.com>
In-Reply-To: <6ad57278$1@news.ausics.net>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <6ad771ad$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 29
X-Complaints: abuse@ausics.net
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.ausics.net!not-for-mail