Strange math behaviour... could someone explain this ?
Mark Wieder
mwieder at ahsoftware.net
Sat Oct 8 12:23:40 EDT 2005
Alex-
Friday, October 7, 2005, 11:14:47 AM, you wrote:
> It's NOT a Rev bug - it's an artifact of double precision binary
> arithmetic (or, if you like, an artifact of the IEEE format used by
> Intel (and everyone else)).
I'm sure if I coded the same thing in java I would also come up with
179. It's an artifact of trying to force an analog world into a
digital frame and back again. You can see the same sort of thing at
work if you look into "random" numbers.
However, 36-34.2 = 179 is just WRONG.
While it's easy to rationalize the error by examining the inaccuracies
due to the constraints forced by the math libraries, the real-world
consequences become more apparent when the discrepancy is a larger
percentage of the result.
Try this:
on mouseUp
local t1
put 36 - 34.2 into t1
add .2 to t1
put t1 && "+" && t1 && "=" && trunc(t1+t1)
end mouseUp
I'd be happiest if the trunc() function internally appended a trailing
"" before performing its task, and I think it's worth a BZ enhancement
request entry - jbv, want to do the honors?
--
-Mark Wieder
mwieder at ahsoftware.net
More information about the use-livecode
mailing list