Mod always returns an integer
Monkey Forums/Monkey Programming/Mod always returns an integer
| ||
The Mod operator chops off any decimal part in its operands.Local x#=4.1, y#=3.1 x = x Mod y gets rendered in javascript as var bbt_x=4.2; var bbt_y=3.1; bbt_x=(((bbt_x)|0) % ((bbt_y)|0)); This isn't a bug, because it's been deliberately made to happen, but could it be done better? Which of the targets will only do modulo on integers? |
| ||
We can roll our own floating point Mod withFunction fmod:Float( a:Float, b:Float ) ' a Mod b for floats Return a - b * Int( a/b ) End Take this with a grain of salt. It should be okay with Floats. But I'm a little vague on what happens if an Int is used for one or both arguments. The cross platform behavior could be a problem, especially if the Int is too big for a Float. The built-in Mod is supposed to work with floats in the not too distant future. |
| ||
Yeesh. All because of 'mod='? |