Re: (was Int Function) mod bug
Re: (was Int Function) mod bug
- Subject: Re: (was Int Function) mod bug
- From: John W Baxter <email@hidden>
- Date: Mon, 19 Aug 2002 18:15:41 -0700
At 14:20 +0100 8/19/2002, has wrote:
>
I sympathise with AS's designers here: just as all floating -point values
>
are wrong, no language-level solution will be correct.
Language level solutions can be correct. But they don't use binary
floating point implementations.
One common approach is to say that
22 / 7 (whatever operator one wants to assign the task...in Smalltalk
it's simply /) produces...
22 / 7 The computations on these rational numbers are defined and work
correctly (and in Smalltalk covert to integer if appropriate automatically.
To see that in more familiar form, the pseudo Applescript might be
(22 / 7) as float
^^^^^^^^^
this part isn't real AppleScript
producing
3.14285714286
(note that 22 / 7 is close enough to pi for lots of purposes...I didn't
pick the example accidentally).
To see 22 / 7 as a floating point value
Likewise, mixed operations work right...
22 / 7 + 8 is 78 / 7
The numerator and denominator are kept (in the "complete" implementation)
in integers which expand to be as large as needed. So now you have precise
results which are hard of many of us to read.
Decimal-based floating point can be lots more useful for things like money
calculations than binary floating point is. That's why the old Microsoft
BASIC for the Mac (1984 or 1985) came in two flavors...decimal floating
point (with a $ in the icon) for precision in decimal sorts of
calculations, and binary floating point (the icon replaced the $ with a pi
symbol) for speed.
But in that case, $1.00 / 3 is still a problem (does your favorite grocery
store ring up 3 3 for a dollar items as $0.33, $0.33, $0.34, or as $0.34,
$0.33, $0.33?--I finally saw one do the former recently).
--John
--
John Baxter email@hidden Port Ludlow, WA, USA
_______________________________________________
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.