Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to create nan/inf

by swampyankee (Parson)
on Aug 09, 2008 at 05:28 UTC ( [id://703232]=note: print w/replies, xml ) Need Help??


in reply to How to create nan/inf

iirc, FFFFFFFFFFFFFFFF is NaN on Windows boxes (at least with Intel Visual Fortran and C), but I can't swear that's guaranteed to be true on all x86 machines, let alone all machines using IEEE arithmetic. I know that some platforms, e.g., IBM mainframes, don't have floating point models capable of representing NaN or Inf, so a completely portable solution is impossible.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Replies are listed 'Best First'.
Re^2: How to create nan/inf
by syphilis (Archbishop) on Aug 09, 2008 at 06:22 UTC
    so a completely portable solution is impossible

    That's not really an issue for me. I was just after some way of getting test 6 of PowInt.t to pass on Windows, leaving all other systems unaffected. I think I've now achieved that.

    One of the things that was throwing me was that, on Linux, the strings 'nan' and 'inf' are converted to a nan/inf when used in numeric context. That is, on Linux:
    perl -MDevel::Peek -e 'Dump "inf" + 1';
    outputs:
    SV = NV(0x...) at 0x.... REFCNT = 1 FLAGS = (NOK,READONLY,pNOK) NV = inf
    But there's no comparable behaviour (that I can find) on Windows. The strings '1.#INF' and '1.#QNAN' are not interpreted as inf/nan when used in numeric context. Instead they're just numified according to the usual rules that apply to the numification of strings - ie they take on a numeric value of 1:
    C:\>perl -MDevel::Peek -e "Dump '1.#INF' + 1" SV = IV(0x218fe28) at 0x218fe2c REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,pIOK) IV = 2
    I wasn't expecting such different behaviour - and that added significantly to my confusion.

    Cheers,
    Rob
Re^2: How to create nan/inf
by ikegami (Patriarch) on Aug 09, 2008 at 06:45 UTC

    Double FFFFFFFFFFFFFFFF is *a* IEEE 754 NaN. Anything of the form [7F]FFFxxxxxxxxxxxx where "x" is nonzero is a NaN.

    There are at least two kinds of NaN: signaled and quiet. IEEE 754 doesn't define the how to encode them, but recommends using the most significant bit of "x" (0 for signaled).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found