in reply to How to create nan/inf

You could also create the bit pattern yourself and unpack it. It's system dependant, but it will allow you to generate every possible special value.

For example, Windows uses little-endian IEEE

sub double_from_hex { unpack 'd', scalar reverse pack 'H*', $_[0] } use constant POS_INF => double_from_hex '7FF0000000000000'; use constant NEG_INF => double_from_hex 'FFF0000000000000'; use constant qNaN => double_from_hex '7FF8000000000000'; use constant NaN => qNaN; print(POS_INF, "\n"); # 1.#INF print(NEG_INF, "\n"); # -1.#INF print(qNaN, "\n"); # 1.#QNAN

x86 doesn't seem to have signaled NaNs or they're not recognized when stringified. On the other hand, "FFF8000000000000" is recognized as being "-1.#IND".

Replies are listed 'Best First'.
Re^2: How to create nan/inf
by syphilis (Archbishop) on Aug 09, 2008 at 04:35 UTC
    That gives me (more than) enough to play with :-)
    One of the PowInt.t tests on Math::GSL (version 0.07) fails on Windows but passes on Linux. It's to do with differing treatment of nans and infs. It helps if I can reliably and easily create nans and infs on both platforms - which I now can.

    Thanks ikegami.

    Cheers,
    Rob