Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^7: nans, infs, and vomit

by ysth (Canon)
on Sep 02, 2008 at 06:08 UTC ( #708391=note: print w/replies, xml ) Need Help??

in reply to Re^6: nans, infs, and vomit
in thread nans, infs, and vomit

Try this instead:
$ perl -wle'print "infantile paralysis" + 0' Argument "infantile paralysis" isn't numeric in addition (+) at -e lin +e 1. inf
or even:
$ perl -le'use warnings "FATAL"=>"numeric"; print "infantile paralysis +" + 0'
I guess I'd like to know more about where you are finding this problematic. I don't quite get why you'd be taking arbitrary strings and numericizing them.

Replies are listed 'Best First'.
Re^8: nans, infs, and vomit
by syphilis (Bishop) on Sep 02, 2008 at 10:10 UTC
    I'd like to know more about where you are finding this problematic

    I think it's laughable that the strings "nanny goat", "infantile paralysis", and "anal retentive" should all take on quite different values when used in a numeric context. That's about all there is to *that* aspect of my posts in this thread. (I was quite serious however, about not feeling the need to port that behaviour to Windows.)

    The problematic aspect is just that there's a difference between nix and windows - but that can be worked around. The real *annoyance* is that, sometimes, the workaround is not so simple. And one often has to wend one's way through a series of obstructions to get there (and I still haven't got there, btw). In this particular case, I was looking at a piece of code in one of the Math::GSL tests:
    'gsl_sf_gamma_e(-1,$r)' => 'nan',
    The function (key) on the left hand side will return a nan, and somehow that test passes on linux. But on windows it fails. First thought is that's because the stringification of a nan on Windows isn't 'nan' - so you replace the right hand side with '1.#QNAN', since that *is* the stringification of the nan returned by gsl_sf_gamma_e(-1,$r) on Windows.
    But that doesn't work either, because, although 'nan' numifies to a nan on linux, '1.#QNAN' numifies to 1 on Windows. So, you now realise that test will succeed on all platforms only if the rhs is replaced with something (eg a variable) that actually is a nan on all operating systems. It happens that the Math::GSL module has such a variable. The test passes on all platforms if it is rewritten as:
    'gsl_sf_gamma_e(-1,$r)' => $GSL_NAN,
    But, having submitted a patch to effect that change, you find that, on each subsequent update of the git source, the author has kept silently ignoring that particular patch. Eventually you come to the conclusion that he really *does* want to test:
    'gsl_sf_gamma_e(-1,$r)' => 'nan',
    and the only thing to do is to have that test skipped on windows.

    But the tests are being run in an arcane testing environment (Test::More, Test::Builder, Test::Class) and, while Test::Builder::skip_all() works fine, Test::Builder::skip() apparently does not. (At least I think that's the problem ... I haven't checked thoroughly yet ... I'll get back to it when I finish this post.) All of this because someone decided it would be a great labour saving device to have atof/strtod convert any string beginning with "nan" to a nan.

    Yes - I don't have to do this. But I also don't have to approve of every half-arsed decision that has ever been made.

    One also wonders about the Pandora's Box that is opened by this 'orrible nan/inf handling. On linux, both "nan" and "nano" are numified to a nan. But, while gsl_isnan("nan") returns true, gsl_isnan("nano") is an error. Seems strange, looks like a bug .... doesn't affect Windows, but ;-)


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2020-10-24 04:08 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (242 votes). Check out past polls.