Math.floor bug in Flash

56 views
Skip to first unread message

Tom

unread,
Sep 18, 2014, 11:15:25 AM9/18/14
to haxe...@googlegroups.com
Hi!

There is a bug in flash Math.floor(), Math.ceil(), and Math.round().
If a Float number is greater, than MaxInt, then the above functions return values are wrong.

eg.:

var f:Float = 1411051769698;
trace
( Math.floor(f) ); // output: -1992470686

In pure AS3 this is works very well.
Can be use the native Math functions in flash somehow?

Cheers!
Tom

Tom

unread,
Sep 18, 2014, 11:30:25 AM9/18/14
to haxe...@googlegroups.com
I found a solution for AS3. In Flash the Number type has a toFixed() function, which is a round function.

So the untyped (f - 0.5).toFixed(0); give the correct floored value, but this is a hack, and the Math.floor will give error any big Float number.

Dan Korostelev

unread,
Sep 18, 2014, 11:46:53 AM9/18/14
to haxe...@googlegroups.com
I think that is because it returns Int and result is unspecified for these numbers, as stated in the doc. Try Math.ffloor.

четверг, 18 сентября 2014 г., 19:15:25 UTC+4 пользователь Tom написал:

Tom

unread,
Sep 18, 2014, 12:03:18 PM9/18/14
to haxe...@googlegroups.com
Thanks for you comment. I didn't know about ffloor, and it is working as expected.
Reply all
Reply to author
Forward
0 new messages