• 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: real comparison problems [Re: ASTest redux]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: real comparison problems [Re: ASTest redux]


  • Subject: Re: real comparison problems [Re: ASTest redux]
  • From: Nigel Garvey <email@hidden>
  • Date: Sat, 28 Sep 2002 22:04:11 +0100

has wrote on Sat, 28 Sep 2002 11:41:59 +0100:

>>>Oh, and if anyone has any ideas what I might do to compensate for AS's
>>>stupid treatment of reals, eg:
>>>
>>> 0.7 * 0.7 = 0.49
>>> --> false

>One solution I suppose is to coerce the reals to strings and comparing
>those, except that might then get hung up on a visible rounding error. And
>none of which really helps if the values being tested aren't reals
>themselves, but compound structures such as lists or, worse, records
>containing reals.
>
>I think what I'm really looking for is somebody to say "there is no easy
>way to solve this problem as the fault is AppleScript's", so I can avoid
>the issue myself and just warn the user to be aware of this flaw in AS and
>leave them to deal with it themselves. Put me out my misery. :(

The truncation handlers in my aRounderRound set (on ScriptBuilders) use
some number jiggling to cope with various floating-point problems. They
handle the particular numbers you quote with ease:

set desired_precision to 5 -- say
(trnc from 0.7 * 0.7 onto desired_precision without rounding) = (trnc
from 0.49 onto desired_precision without rounding)
--> true

For your purposes, it *may* be possible to simplify this and just use a
common floating-point multiple:

0.7 * 0.7 * (10 ^ 0.5) = 0.49 * (10 ^ 0.5)
--> true

NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Adding a message to a mailbox in Mail
  • Next by Date: Re: real comparison problems [Re: ASTest redux]
  • Previous by thread: Re: real comparison problems [Re: ASTest redux]
  • Next by thread: Re: real comparison problems [Re: ASTest redux]
  • Index(es):
    • Date
    • Thread