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.


In reply to Re^4: modulo 1 (%1) and fractional part of a number by pryrt
in thread modulo 1 (%1) and fractional part of a number by JBCookin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.