Apologies if this is common knowledge, but I've just come across a huge maths
problem in Flash... as I've mentioned before I'm working on an online trading
system where real people make or lose real money, sometimes a huge amount of
it, so this isn't funny...
Here's some simple arithmetic..
Here's a direct lift from something I posted on the OSFlash list...
This is all to do with floating-point precision and that you can't
represent all numbers exactly (0.1 is one culprit) in the IEE
standard. There are plenty of sites about this - see here, for
example:
I am a bit shocked, too. But yeah, I think you are right, I tried it
with the subtraction assignment (-=), too and I have the same return.
The second queer thing is that Macromedia says:
The following statement subtracts the floating-point number 1.5 from
the floating-point number 3.25 [ 3.25
Thanks Ian... I was aware of the problem in general from experiences with Java,
but I guess I'd ignored them.
I'm multiplying by 100 and dividing by 100 also. If I'd written this system
from scratch i'd have created my own numeric class and represented floating
point numbers as 2 seperate
There is a way to work around it though. The number of numbers between two
integers drops as the number grows, so if you represent your number by
splitting it into more variables, then the precision of your arithmetic will
grow as well.
Try this:
var a:Number = 1.9;
var b:Number = 2.2;
var c =
Apologies if this is common knowledge, but I've just come across a
huge maths problem in Flash... as I've mentioned before I'm working
on an online trading system where real people make or lose real
money, sometimes a huge amount of it, so this isn't funny...
You are right. It's very not
6 matches
Mail list logo