What I *think* (after some testing) is going on is that the Math::BigInt and Math::Bigfloat overload the arithmetic operators, which breaks timegm().

No, overloading of operators is based only on the arguments given to them. But 'use bignum;' overloads numeric constants. So, for example:

timegm(0,0,0,$day,$month,$year)

becomes

timegm( Math::BigInt->new(0), Math::BigInt->new(0), Math::BigInt->new(0), $day, $month, $year )

And Math::BigInt might not be careful enough to have Math::BigInt->new(0) act enough like just plain 0 for timegm()'s usage (not surprisingly).

Is this expected behavior and/or documented anywhere?

It sounds like you probably read the first sentence of the bignum documentation. Perhaps you failed to go on to read the second sentence.

This makes bignum.pm a cute demonstration that can be convenient for a one-liner. Otherwise, you should just use Math::BigInt and/or Math::BigFloat directly, so you can avoid making every single time you use a numeric constant magically turn into a complex object that infects the results of any computations that touch it.

Most of the time you only even need to call Math::BigInt->new() once, so a wrapper like bignum.pm seems of dubious benefit. bignum.pm should probably come with a big warning like "This transforms simple-looking Perl code into something very different and can easily break code".

- tye        


In reply to Re: Bignum breaks Time::Local? (constants) by tye
in thread Bignum breaks Time::Local? by cunningrat

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.