Detecting +/-1.#J

This is a discussion on Detecting +/-1.#J within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, How do I detect when the answer to a sum is infinity? I need to implement it into ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    128

    Detecting +/-1.#J

    Hi everyone,

    How do I detect when the answer to a sum is infinity? I need to implement it into the following code:

    Code:
    if (Number == (Infinity))
        MessageBox(hwnd, "Enter a number above zero.", "Error", MB_OK);
        break;
    It is a division sum.

    Thanks.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    See fpclassify or isinf ;-). The latter does just that.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,158
    Why not check if the denominator is zero before dividing?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    128
    Thanks.

    I tried the check for 0, but it didn't seem to work for division sums.

    Please could you show me how to use the isinf() operation?

    Thanks.
    Last edited by george7378; 05-17-2010 at 11:15 AM.

  5. #5
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    Well, look up a reference for that - you should really have one. Or use an online one, there are plenty. Basically, it's very simple: if (isinf(num)) ...;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting Keys
    By Sn0wcra5h in forum C Programming
    Replies: 1
    Last Post: 01-21-2010, 10:18 PM
  2. Detecting Edit Control Text
    By yoonkwun in forum Windows Programming
    Replies: 2
    Last Post: 07-12-2009, 08:48 AM
  3. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  4. Detecting the OS
    By John.H in forum C++ Programming
    Replies: 3
    Last Post: 02-21-2003, 08:50 AM
  5. Detecting CD drive letters in the Win32 API...
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 10-07-2002, 02:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21