Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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

by tye (Sage)
on Nov 05, 2012 at 23:34 UTC ( #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( 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 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 seems of dubious benefit. should probably come with a big warning like "This transforms simple-looking Perl code into something very different and can easily break code".

- tye        

Comment on Re: Bignum breaks Time::Local? (constants)
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2015-10-13 12:52 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (306 votes), past polls