[REBOL] Re: mathematical rounding...
From: ryanc:iesco-dms at: 6-Nov-2001 9:27
Here are some ones I tried that seem to be real fast:
; This is fastest, but is limited to positive integers.
round: func [n] [
to-integer n + .5
]
; This is the fastest for working with large decimals, but only does
positive numbers...
round: func [n] [
(n + .5) - ((n + .5) // 1)
]
; This does positive and negatives fine...
round: func [n] [
(n: either n < 0 [ n - .5 ] [ n + .5 ]) - (n // 1)
]
; If you need to certain places do this:
to-thousandth: func [n] [
(n: either n < 0 [ n - .0005 ] [ n + .0005 ]) - (n // .001)
]
You can test your own with the program I have been using to improve my ray
casters performance:
do http://www.sonic.net/~gaia/misc/benchmark.r
--Ryan
Media wrote:
> hi,
>
> What's the fastest algorythm to do rounding of decimal numbers... since
> rebol does not seem to have an explicit rounding function...
>
> to-integer only truncates...
>
> thanks!
>
> Max
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
The contradiction so puzzling to the ordinary way
of thinking comes from the fact that we have to use
language to communicate our inner experience
which in its very nature transcends lingistics.
-D.T. Suzuki