Article View: comp.lang.forth
Article #126ROUND function
From: dxf
Date: Sun, 18 Oct 2026 16:09
Date: Sun, 18 Oct 2026 16:09
34 lines
1513 bytes
1513 bytes
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 ; :noname cr begin refill while source 2dup type space evaluate cr repeat ; execute 876.543e 3 round f. 876.543 876.543e 2 round f. 876.54 876.543e 1 round f. 876.5 876.543e 0 round f. 877. 876.543e -1 round f. 880. 876.543e -2 round f. 900. 876.543e -3 round f. 1000. 456.789e 3 round f. 456.789 456.789e 2 round f. 456.79 456.789e 1 round f. 456.8 456.789e 0 round f. 457. 456.789e -1 round f. 460. 456.789e -2 round f. 500. 456.789e -3 round f. 0. +nan 3 round f. +NAN -inf -3 round f. -INF
Technical Details
Message-ID:
<6ad4ef23$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-mailShow Full Headers
Complete Article Headers
Date: Mon, 19 Oct 2026 03:09:07 +1100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Newsgroups: comp.lang.forth Content-Language: en-GB From: dxf <dxforth@gmail.com> Subject: ROUND function Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit NNTP-Posting-Host: news.ausics.net Message-ID: <6ad4ef23$1@news.ausics.net> Organization: Ausics - https://newsgroups.ausics.net Lines: 34 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