in reply to Re^3: modulo 1 (%1) and fractional part of a number
in thread modulo 1 (%1) and fractional part of a number
I agree that making an edge case for 1, specifically, would be DWIMmery. But I think that the current implementation of truncate floating points to integers before applying an integer modulo, unless the divisor happens to be bigger than UV_MAX+1; oh, and by the way, we're going to require you to study perlguts to know that UV_MAX is the same number of bits as IV_MAX, but unsigned, and that UV_MAX+1 can thus be calculated from $UV_MAX_PLUS_ONE = 256**$Config{ivsize}. Personally, I think it should only use the integer moduluo if both operands are integers that fit within ivsize; otherwise, if either operand is recognizably floating point (ie, has a fractional component, or is too big for IV), then use floating-point modulo. Or, be like C and never make exceptions: have separate operators for integer modulo and floating modulo. The Perl implementation has too many DWIM DWTPM-isms for my tastes.
But yes, since it's so easy to define the custom function as hippo did, that's the best choice for Perl at this stage in the game.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: modulo 1 (%1) and fractional part of a number
by LanX (Saint) on Sep 14, 2018 at 17:04 UTC |