Thread: Checking For 1.#INF and 1.#IND

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    3

    Checking For 1.#INF and 1.#IND

    Does anyone know how to check if a double variable has 1.#INF, -1.#INF, 1.#IND?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://www.daemon-systems.org/man/isnan.3.html
    Not entirely portable as far as I can tell.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Apparently VC++ has _isnan if you're using that compiler: http://www.parashift.com/c++-faq-lit...html#faq-29.15

    You can also compare against infinity:
    Code:
        if (std::numeric_limits<double>::has_infinity && d == std::numeric_limits<double>::infinity())
            std::cout << "Infinity!\n";
    Although I don't know any caveats or details about this.

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    3
    Thanks Salem....... I will look into it.

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    3
    Thanks Daved....... I will look into it.

  6. #6
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    I believe one of the boost guys was working on a portable is_nan library. if you search the boost dev mailing list you should be able to find something on it.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. -1.#IND in output???
    By alyeska in forum C++ Programming
    Replies: 4
    Last Post: 01-19-2008, 01:32 AM
  2. Rotations, Radians and -1.#IND oh my
    By Cdrwolfe in forum C++ Programming
    Replies: 6
    Last Post: 06-19-2007, 04:43 AM
  3. Decimal problem -1.#IND
    By lynnluoll in forum C++ Programming
    Replies: 2
    Last Post: 05-23-2005, 04:23 PM