Thread: how to set value equal to infinity

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    4

    how to set value equal to infinity

    if TEST is a variable, then how can i set this variable,Test, equal to infinity.
    When i have already set it to infinity, how can i check it that it is already set to infinity.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    http://www.roguewave.com/support/doc...s.html#idx1018

    Another way of doing it using numeric_limits. See the infinity() and quiet_NaN() member functions.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    numeric_limits does not work in general; IEEE floating point formats support the notion of "not a number" (NaN) or of infinity. Other floating point formats do not. The infinity() and quiet_NaN() members numeric_limits have no effect if your compiler supports a format that doesn't support them.

    The general approach if you want to represent infinity and other concepts that are not supported universally by floating point formats is to write your own class which manages (conceptually) a floating point value and a set of boolean flags.

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Presumably, if you are looking for infinity and NaN, then you ought to use the bool members of numeric_limits that tell you if the type has them as well... doing otherwise does not make sense.
    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I think there are functions (in C99) like nan() and setnan().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set ARRAY to INFINITY!
    By davewang in forum C Programming
    Replies: 13
    Last Post: 12-04-2008, 07:12 AM
  2. Replies: 7
    Last Post: 08-19-2007, 08:10 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  5. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM