cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Math.floor, Math.ceil, Math.trunc should return double (num) to avoid overflow

Math.floor, Math.ceil, Math.trunc should return double (num) to avoid overflow

Math static methods are not equivalent to the deprecated Flexscript commands that they replace.

 

Flexscript command floor has a type signature "num floor(num)", Math class method has a type signature "int Math.floor(double)". It may lead to overflow issues when working with large numbers (such as DateTime values).

 

This is the code to reproduce this issue:

double n = xxx-xxxxxxxx;
return
[ floor(n), "!=", Math.floor(n) // overflow: xxx-xxxxxxxx, !=, -2147483648
, ceil(n), "!=", Math.ceil(n) // overflow: xxx-xxxxxxxx, !=, -2147483648
, round(n), "==", Math.round(n) // OK
, trunc(n), "!=", Math.trunc(n) // overflow: xxx-xxxxxxxx, !=, -2147483648
];

 

sastanin_0-1753437058919.png


Math.round works correctly.

 

Reproducible in FlexSim 25.2.0 Beta build 94 and earlier versions.

 

This doesn't happen in Javascript, which was probably the inspiration for the Math class:

sastanin_1-1753437107640.png

 



Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea