Re: magic integer converter number 62?
Re: magic integer converter number 62?
- Subject: Re: magic integer converter number 62?
- From: Deivy Petrescu <email@hidden>
- Date: Fri, 23 Feb 2001 09:54:03 -0500
OK, this has gone on quite long enough. The basic problem has to do
with the limitations of finite-precision numbers. What scripting
additions you have installed makes no difference, but the version of
AppleScript does, since we've tweaked the behavior several times.
(Obviously, it's still not quite right.)
AppleScript does its floating point math using IEEE double-precision
numbers, which are stored as a fractional part from zero to one and an
exponent, both in binary. The tricky bit is that many numbers that look
clean to us (e.g. 232 or 0.6) are long repeating "decimals" in binary,
and therefore can't be stored exactly given a finite number of bits --
in this case, 48.
In most cases, this doesn't matter much -- you're only interested in the
first few decimal places anyway, and the inaccuracy is down around the
12th decimal place. However, naive div and mod will amplify these
errors, so you have to fudge things slightly to come up with the "right"
answer. If it's done wrong, you wind up with answers that are off by
one from what you expect, or numbers that look like they're integral but
aren't. Additionally, "as integer" has always been extremely intolerant
of low-order noise. This is all on our list of things to fix for
post-1.6.
--Chris Nebel
AppleScript Engineering
Appologies twice for the double reply and for persisting on the subject.
The explanation did not convince me.
First: it should work the same with 61 or 62 or show a pattern work
not work every 2 powers of 2.
Second: Paul originally argued that 62 +2 = 64 and that was what was
going on. He was right. It does not explain, on the contrary shows
another problem, namely, the expression:
set b to ((x + (2.6 - (2.6 mod 1))) - x) as integer
should, according to the rules of precedence, be computed inside
out. That is, one should get 0.6 (or its periodic representation in
binary) before adding or subtracting from x. Since, if one changes
the number 2.6 to 3.6, 61 works fine and so does -67, this indicates
that there are some sums going on before the due time.
My Graphing Claculator shows 2 to the power 1024 is infinity. Looking
at the binary expansion for .10 or .60, I do not have a clue as to
why 62 works and 61 doesn't. IEEE or not.
Regards
Deivy Petrescu
http://www.dicas.com
Tips for your Mac.
Dicas para o seu Mac.
mailto:email@hidden
mailto:email@hidden