I have an int a that needs to be equal to “infinity”. This means that if
int b = anyValue;
a>b is always true.
Is there any feature of C++ that could make this possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Integers are finite, so sadly you can’t have set it to a true infinity.
However you can set it to the max value of an int, this would mean that it would be greater or equal to any other int, ie:
is always true.
You would do this by
This will normally be equal to 2,147,483,647
If you really need a true “infinite” value, you would have to use a double or a float. Then you can simply do this
Additional explanations of numeric limits can be found here
Happy Coding!
Note: As WTP mentioned, if it is absolutely necessary to have an int that is “infinite” you would have to write a wrapper class for an int and overload the comparison operators, though this is probably not necessary for most projects.