Re: magic integer converter number 62?
Re: magic integer converter number 62?
- Subject: Re: magic integer converter number 62?
- From: Chris Nebel <email@hidden>
- Date: Fri, 23 Feb 2001 14:08:21 -0800
- Organization: Apple Computer, Inc.
Deivy Petrescu wrote:
>
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.
Sorry, I've already deleted most of the messages in this thread, so I don't
have the full history any more. You didn't say what version of AppleScript
you're using, but I'm guessing that it's something older than 1.4, because
that expression always yields 2 for me no matter what x is.
The key in this case is that 2.6 mod 1 doesn't actually give 0.6, it gives
0.6 + e, where e is about 1.11e-16. In other words, it's off by the
lowest-order bit in a double. If you subtract that number from x.6 when x
is non-zero, the erroneous bit drops off the end, but if you do the right
things (e.g. 0.6 - (2.6 mod 1)), you can see it, and it's enough to throw
off "as integer."
>
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.
The maximum value for a double isn't 2^1024, it's 2^1024 - e (e as above).
--Chris Nebel
AppleScript Engineering