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
ROUND function
- From
- dxf <dxfo…@gmail.com>
- Organization
- Ausics - https://newsgroups.ausics.net
- Message-ID
- <6ad4…@news.ausics.net>
- Date
- Newsgroups
- comp.lang.forth