• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: a numeric bug.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a numeric bug.


  • Subject: Re: a numeric bug.
  • From: Doug McNutt <email@hidden>
  • Date: Thu, 15 Sep 2005 14:35:10 -0600

At 10:38 -0700 9/15/05, Christopher Nebel wrote:
>Sure, but that's not how the internal representation of numbers in  AppleScript works.  It's using IEEE 754 double-precision numbers,  which use mantissa * 2**exponent, which is notoriously inaccurate  when representing powers of 10.  (10 is an infinite repeating decimal  in base 2.)

Chris is probably slapping himself by now. I feel a bit guilty jumping on a fine gentleman.

10 (2) = 1010 exactly.

 1/10 = 0.1 (2) = 0.0001100110011. . . forever.

Unless the exponent is large enough that binary rounding after 52 bits is required, decimal integers can be handled exactly as IEEE doubles. That's about 10^15 but each power of ten ( 2*5 ) introduces a zero at the right end so 10^J can be carried exactly to something like J +52 bits which is why the OP got to 10^23 before a failure.

It's decimal fractions that cause all of the trouble. Back to pieces of eight and all would be well.

In most modern machines internal calculations are carried to 68 bits but  the last 16 bits are lost when a number is stored as a double. It would be interesting to know if AppleScript saves intermediate results in an 80 bit hardware register to preserve the higher precision in a formula. The loop used by the OP almost surely requires storage. Could it be rewritten so that it doesn't?

--
-->The Creator is the God who provided the void and the rules that matter and energy must live by in order to exist in it. Intelligent designers and engineers create useful stuff while abiding by the rules.<--
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: a numeric bug. (From: has <email@hidden>)
 >Re: a numeric bug. (From: Emmanuel <email@hidden>)
 >Re: a numeric bug. (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: exit this repeat loop
  • Next by Date: convert AS syntax to CLI
  • Previous by thread: Re: a numeric bug.
  • Next by thread: Re: a numeric bug.
  • Index(es):
    • Date
    • Thread