Since the dawn of computing in the 1950s, it has clearly been understood that
"Thou shalt not compare floating point numbers for equality"

It is not supposed to work.

It only rarely does work(every now and again you will get lucky depending on the number that you chose to test). If you change hardware architecture or change the implementation of some parsing or manipulation your code will change behaviour - not very desirable.

It is not a bug.

You should not do it.

If you want to know that 2 floating point numbers are "close enough" to be considered as the same value, then subtract them and check to see if the absolute value of their difference is less than your criteria for "sameness". That has been the correct way to compare floating point numbers for about 50 years and until we stop using binary components to build computers, it will persist.

Ron

elibol wrote:
I came to this specific value from 6.3e51. Here are some more tests:

var test1_str:String = "6.3e51"; //6.3e+51 outputs same result.
var n1:Number = parseFloat(test1_str);
trace(n1);
trace(n1 == (6.3e51));
trace(6.30000000000000e+51 == 6.3e+51);
trace(n1-(6.3e51));

//AS3
6.30000000000000e+51
false
true
1.32922799578491e+36

It may certainly be by design, but aren't these unexpected results? as2 and
java do not behave this way. The parseFloat function is flawed.

I will post a comment on livedocs, and I've submitted the issue as a bug at
http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

I am not going over board am I? I just need my program to work correctly.

On 3/5/07, Fumio Nonaka <[EMAIL PROTECTED]> wrote:

I am not sure whether it is a bug or by design, though.

var test0_str:String = "6.30000000000000e+51";
var n0:Number = parseFloat(test0_str);
trace(n0);
trace(n0 == (6.30000000000000e+51));
trace(n0-(6.30000000000000e+51));
// ActionScript 3.0
6.30000000000000e+51
false
1.32922799578491e+36
// ActionScrpt 2.0
6.3e+51
true
0

Decrease one digit:

var test1_str:String = "6.3000000000000e+51";
var n1:Number = parseFloat(test1_str);
trace(n1 == (6.3000000000000e+51));
trace(n1-(6.3000000000000e+51));
// ActionScript 3.0
true
0
_____
elibol wrote:
> Those who are interested in helping me verify the problem can run this
test
> in actionscript 2.0 and again in actionscript 3.0.
>
> var a:String = "6.30000000000000e+51";
> var b:String = "23";
> var c:Number = parseFloat(a)%parseFloat(b);
> trace(c); //outputs 7 in as3, and 18 in as2
> trace(6.30000000000000e+51%23); // outputs 18 in both as2 and 3

Good luck,
--
Fumio Nonaka
mailto:[EMAIL PROTECTED]
http://www.FumioNonaka.com/
My books<http://www.FumioNonaka.com/Books/index.html>
Flash community<http://F-site.org/>

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to