Integer infinity?

This is a discussion on Integer infinity? within the C Programming forums, part of the General Programming Boards category; Hey, For comparing purposes I want to make an integer essentially "infinity" (meaning any int compared to it will be ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    Integer infinity?

    Hey,

    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"??

    Thanks!!

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,305
    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-20-2009, 11:37 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05: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, 09:43 AM

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