Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl returns NaN after addition

by syphilis (Chancellor)
on Oct 17, 2013 at 01:35 UTC ( #1058577=note: print w/replies, xml ) Need Help??


in reply to Perl returns NaN after addition

Could it be that it's too large for perl? or it could be a non-numeric variable in the data file, so how would I test for that?

You can get a result of "NaN" by doing addition *only* if one (or more) of the values being summed is a NaN.
I would therefore check the terms being added to see if any of them match the regex /^nan/i .

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Perl returns NaN after addition
by tinita (Parson) on Oct 17, 2013 at 01:42 UTC
    or, if the OP happens to use Math::BigFloat:
    $ perl -MMath::BigFloat -wE 'say Math::BigFloat->new(5) + "foo"' NaN
      or, if the OP happens to use Math::BigFloat

      It's interesting that Math::BigFloat decides it has to numify a non-numeric string to NaN ... when everything else numifies such a string to zero.

      Actually, I'm tempted to s/interesting/stupid/, but maybe there's a precedent somewhere that gives some credence to the Math::BigFloat behaviour.

      Cheers,
      Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058577]
help
Chatterbox?
[Corion]: Hmm - I think I'm not really making friends at $work. "We" (as in $current_project) should enter some Changes into the system, and I just told the Transition Manager, who should do that or tell somebody to do that to learn the system in which they ...
[Corion]: ... should create that Change.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2017-10-23 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (279 votes). Check out past polls.

    Notices?