Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Bignum breaks Time::Local? (constants)

by tye (Sage)
on Nov 05, 2012 at 23:34 UTC ( [id://1002399]=note: print w/replies, xml ) Need Help??


in reply to Bignum breaks Time::Local?

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        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1002399]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-19 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found