Hm. $x starts undefined

[0] Perl> use Devel::Peek;; [0] Perl> Dump $x;; SV = NULL(0x0) at 0x3c6d400 REFCNT = 1 FLAGS = ()

You set $x to the maximum unsigned integer value; it becomes an IV:

[0] Perl> $x = ~0;; [0] Perl> Dump $x;; SV = IV(0x3c6d3f8) at 0x3c6d400 REFCNT = 1 FLAGS = (IOK,pIOK,IsUV) UV = 18446744073709551615

You add 2 to it, it overflows the IV, so perl converts it to an NV (NB: No NaN arises from the overflow of the IV.)

[0] Perl> $x += 2;; [0] Perl> Dump $x;; SV = PVNV(0x3cb85e8) at 0x3c6d400 REFCNT = 1 FLAGS = (NOK,pNOK) IV = -1 NV = 1.84467440737096e+019 PV = 0

Then, you raise that NV to the power 35; and the NV overflows; resulting in an NV with the floating point value of positive infinity (1.#INF) (NB:the "result to large" error):

[0] Perl> $x **=35;; [Result too large] Perl> Dump $x;; SV = PVNV(0x3cb85e8) at 0x3c6d400 REFCNT = 1 FLAGS = (NOK,pNOK) IV = -1 NV = 1.#INF PV = 0

You then divide the NV 1.#INF, by itself, and you produce an indeterminate floating point value (1.#IND):

[0] Perl> $x /= $x;; [0] Perl> Dump $x;; SV = PVNV(0x3cb85e8) at 0x3c6d400 REFCNT = 1 FLAGS = (NOK,pNOK) IV = -1 NV = -1.#IND PV = 0

The (special form of) NaN was produced by operating upon (erroneous) floating point (NV) values; not integer (IV) overflow.

NaN is a purely floating point concept, and cannot arise as a result of integer overflow.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^12: NaN output by BrowserUk
in thread NaN output by spikeinc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.