real comparison problems [Re: ASTest redux]
real comparison problems [Re: ASTest redux]
- Subject: real comparison problems [Re: ASTest redux]
- From: has <email@hidden>
- Date: Sat, 28 Sep 2002 11:41:59 +0100
John W Baxter wrote:
>
>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
>
>
The way to avoid that particular aspect of the nature of binary floating
>
point is not to compare floating point values for equality. Decide how
>
much of a difference is appropriate to the task at hand to indicate "not
>
equal", and compare that for greater than the absolute value of the
>
difference of the two values.
Hi, yeah. However, I think that's supposed to be AS's job. The problem with
the above example is that _it's_ the one saying "0.7*0.7-->0.49", but then
declares it _not_equal_ when comparing that value to a literal 0.49. It'd
be different if "0.7*0.7" visibly returned "0.489999999999" - your solution
would work there - but it doesn't.
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. :(
(Plus I should probably submit it to Radar abd hope one day it might be
resolved...<sigh>)
Thanks,
has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.