in reply to Re^4: NaN output
in thread NaN output

NaN is a purely floating point concept

It occurs to me that there is indeed a way (in perl) to generate a NaN using only integer values:
C:\>perl -le "$x = (2**1025) / (2**1025);print $x;" -1.#IND
(For those unfamiliar with MS Windows notation, -1.#IND is one of the ways that it represents a NaN)

This, of course, doesn't contradict anything you've said. And it would take some clever legalese to show that this example proves that NaN *can* result from integer overflow ;-)

But it might count as a "trick" method of generating a NaN in perl using only integer values.
NOTE: If your perl's NV is a long double, then 1025 probably won't be a large enough power to generate the NaN.

Cheers,
Rob

Replies are listed 'Best First'.
Re^6: NaN output
by Laurent_R (Canon) on Mar 05, 2014 at 23:07 UTC
    Yep, this is what I get on Cygwin:
    $ perl -e '$x = (2**1025) / (2**1025);print $x;' nan
    But, of course, I am not claiming this to prove my original assumption in any way. We are talking here about manipulating numbers many many orders of magnitude larger, nothing to do with the usual integer overflow.
Re^6: NaN output
by BrowserUk (Patriarch) on Mar 06, 2014 at 06:42 UTC
    generate a NaN using only integer values ... 2**1025

    Whilst that construction uses 2 integer constants, the resultant value is not an integer.

    Similarly, this uses two integers in it construction, but the result is not an integer value: 1/7.

    I'll repeat it. "NaN is a floating point value and thus has nothing at all to do with numerical limits of integer data types."

    Like it, lump it, or obscure it. That remains true.


    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.
      I'll repeat it.

      Oops ... was that for *my* benefit ?
      You're not telling me anything (here) that I don't already know.
      However, looking back at my posts, at no time did I state that explicitly ... though I did make a couple of attempts to make it implicitly apparent - eg a reference to "trick" and the acknowledgement that I wasn't contradicting anything you had said.

      I did think it worthy of mention (but even that's probably debatable in hindsight) that in perl you can start with integers and operate on them in such a way that you derive a NaN - because you can't do that in (eg) C, afaik.

      I also wondered whether that might have been something like the pathway that led Laurent_R to the view that you could get a NaN from integer overflow.
      But it seems Laurent_R was alert to that aspect, anyway.

      Cheers,
      Rob
        You're not telling me anything (here) that I don't already know.

        And what was there in your post that you thought that I didn't already know?

        All I said was, you cannot get NaN from integer overflow. That was, is and always will be true.

        How Laurent_R's misunderstanding came about is irrelevant; that it should be corrected isn't.


        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.