Strange math behaviour... could someone explain this ?
Lynch, Jonathan
bnz2 at cdc.gov
Fri Oct 7 09:31:46 EDT 2005
Even just this simple line produces the same error:
answer trunc((36-34.2)*100)
This is odd...
Look at the results I get when testing this:
Trunc((36-34.1)*100) should = 190, but returns 189
Trunc((36-34.2)*100) should = 180, but returns 179
Trunc((36-34.3)*100) should = 170, and in fact does return 170
Trunc((36-34.4)*100) should = 160, and in fact does return 160
Trunc((1.8)*100) returns 180, like it should
Trunc((1.9)*100) returns 190, like it should
So...
Somehow, Rev is performing 36-34.2, and even though it displays that
number as 1.8, it must be processing it internally as
1.799999999999999999999999999 or something like that.
Very disturbing - This could affect a program of mine.
It is easily worked around, with a function like this:
function trueTrunc pNumber
set the itemdelimiter to "."
return item 1 of pNumber
end trueTrunc
But still, trunc should work properly. That makes me wonder if any other
math functions might have some underlying weirdness.
-----Original Message-----
From: use-revolution-bounces at lists.runrev.com
[mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of Lynch,
Jonathan
Sent: Friday, October 07, 2005 9:13 AM
To: How to use Revolution
Subject: RE: Strange math behaviour... could someone explain this ?
I get the same thing...
That's gotta be a bug.
-----Original Message-----
From: use-revolution-bounces at lists.runrev.com
[mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of jbv
Sent: Friday, October 07, 2005 7:17 AM
To: How to use Revolution
Subject: Strange math behaviour... could someone explain this ?
Hi list,
example 1 :
put 1.8 into myA
put trunc(myA * 100) into myA
in that case, myA=180 which is OK
------------------
example 2 :
put 34.2 into myA
put 36 into myT
if myA > 0 then
if myA < myT then
get myA
put myT - myA into myA
put it into myT
else
put 0 into myA
end if
end if
put trunc(myA * 100) into myA
in that case, myA=179 ?????????????????????
Best,
JB
_______________________________________________
use-revolution mailing list
use-revolution at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
_______________________________________________
use-revolution mailing list
use-revolution at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list