Thread: Using NaN in c++

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Arrow Using NaN in c++

    Is it possible to assign a double to NaN in c++ like:

    Code:
    double number = NaN;
    Suggestions welcome...

  2. #2
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    Try typing it into a compiler and seeing if it compiles/runs correctly.
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: Using NaN in c++

    Originally posted by Hardboy
    Is it possible to assign a double to NaN in c++ like:

    Code:
    double number = NaN;
    Suggestions welcome...
    If you want to go down to that level and as your code will now not be portable among architectures, you might as well use inline assembler....

    Code:
    __asm
    {
    //your instructions here
    }

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    70
    Exercise for hardboy:


    double NaN = 0.0 / 0;

    double NaN = 1.0 / 0; // this one for infinite and NaN

    and

    int _isnan( double NaN );

    int _finite( double NaN );

    these two for testing the infinity or NaN characteristics


    But before you begin, turn off hardware exceptions (you need not to do it in Win32, they are turned off already)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Returning Nan or Inf
    By magda3227 in forum C Programming
    Replies: 4
    Last Post: 07-01-2008, 05:41 PM
  2. nan disappear when printing
    By liats80 in forum C Programming
    Replies: 10
    Last Post: 02-03-2008, 02:17 PM
  3. double, NaN, and super small numbers
    By nbo10 in forum C Programming
    Replies: 5
    Last Post: 08-17-2007, 06:50 PM
  4. a question about nan
    By FOOTOO in forum C Programming
    Replies: 14
    Last Post: 04-26-2007, 01:19 PM
  5. What is a NaN ?
    By anupamjamatia in forum C Programming
    Replies: 5
    Last Post: 08-08-2006, 06:04 AM