Trying the very simple code
round (123 * (9 ^ 10))
returns
-6.22248277E+8
( was 4.28874481323E+11 under Snow Leopard)
on my OS 10.7 machine. Is this happening everywhere or just a very strange thing on my machine???
(I used copy / paste to exclude the possibility of hallucinations.)
Some feedback if this happens to other people as well is welcome.
OS 10.7
Mac mini 2.3 GHz Intel Core i5
Puzzled regards, Jürgen
Some reply to my own post: The problem seems to be related to the 32 bit limit of integers:
set X to (2 ^ 31) - 1
log (round X)
set X to (2 ^ 31)
log (round X)
gives the following “Replies”
tell current application
round 2.147483647E+9
--> 2.147483647E+9
(*2.147483647E+9*)
round 2.147483648E+9
--> -2.147483648E+9
(*-2.147483648E+9*)
end tell
Pretty nasty, I think.
Jürgen
It’s not so much a 10.7 thing as a 64-bit thing. Run in 32-bit in Lion and you’ll get the other result.
Hi Shane,
thanks for pointing out that it is a 64 bit issue. Makes perfect sense in a two˜s complement world.
Since “div 1” does not have that problem, I will rewrite some code to make it more robust.
Jürgen
Using div 1 is also much more efficient, being a built-in operator rather than a scripting addition command.