Re: {aReal} as integer
Re: {aReal} as integer
- Subject: Re: {aReal} as integer
- From: Nigel Garvey <email@hidden>
- Date: Wed, 20 Jun 2001 11:35:53 +0100
Olof Hellman wrote on Tue, 19 Jun 2001 14:00:02 -0700:
>
1.1 as integer
>
--> Error: can't make 1.1 into an integer
>
>
{1.1} as integer
>
--> 1
>
>
{1.9} as integer
>
--> 2
>
>
Is this how it is supposed to work? Seems to obey the IEEE rounding
>
convention ( round to nearest, and if two integers are equally near, then
>
round to even }
That's very interesting! It works for numeric strings as well (one per
list) and is about three-and-a-half to four times as fast as 'round'. I'm
happy to report though (:-)) that my handler is three to six times as
fast as it (depending on the number):
on rndIEEE(n)
if (n mod 2) ^ 2 > 0.25 then return n div 0.5 - n div 1
n div 1
end r2
This is quite surprising when you compare the methods visually, and it
ties in with what Shane's been saying in another thread: that simpler
source code doesn't necessarily mean a more efficient process.
Olof's discovery is fascinating though. If it turns out not to be due to
some bug, it would make a good compromise between simplicity and
efficiency when rounding to the IEEE convention.
NG