Thread: Integer infinity?

  1. #1
    Registered User
    Join Date
    Apr 2008

    Integer infinity?


    For comparing purposes I want to make an integer essentially "infinity" (meaning any int compared to it will be smaller). I know math.h has a float infinity, but trying to cast it as an int make the compiler freak out. Is there any way to make an integer "infinity"??


  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    No, there is no such thing.
    However you don't need such a thing to obtain code that operates as if "any int compared to it will be smaller". You can for example use a longer integer type than the type in the data you are finding the maximum of. Or you can use a boolean flag. Or you can simply use the largest value the integer can hold in some cases, since if the maximum is equal to that then the answer is already correct.

    If that doesn't give you enough information then you'll need to post a code sample of where you want to use this idea.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM