How about this function for rounding positive or negative numbers:

round: func [R [integer! decimal!]][
    to-integer R + (-1 * to-integer negative? R) + .5
]

Shows one of the lesser-known uses of logic values in REBOL :-)


On 18-Nov-1999/22:19:59-6:00, [EMAIL PROTECTED] wrote:
>But Russell,, if you do that with a negative number, you round in the wrong
>direction, yes?
>
>Kat
>
>----- Original Message -----
>From: <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Thursday, November 18, 1999 9:43 PM
>Subject: [REBOL] Round function Re:
>
>
>> I've always rounded by unconditionally  adding 0.5 then converting to
>> integer
>> Russell [EMAIL PROTECTED]
>> ----- Original Message -----
>> From: <[EMAIL PROTECTED]>
>> To: <[EMAIL PROTECTED]>
>> Sent: Thursday, November 18, 1999 8:00 PM
>> Subject: [REBOL] Round function
>>
>>
>> > ; It's fairly basic, but does the job.
>> >
>> > Round: func [R [integer! decimal!]] [
>> > to-integer either 0.5 <= remainder R 1 [R + 1][R]
>> > ]
>> >
>> > Any one got any other maths functions?
>> >
>> > Andrew Martin
>> > [EMAIL PROTECTED]
>> > http://members.xoom.com/AndrewMartin/
>> > Online @ 33,600 Baud!
>> > -><-
>> >
>> >
>>
>>
>
-- 
                           Bohdan "Bo" Lechnowsky
                           REBOL  Adventure Guide
           REBOL Technologies 707-467-8000 (http://www.rebol.com)
          Download the REBOL Messaging Language for all Platforms

Reply via email to