Link to home
Start Free TrialLog in
Avatar of antoniogm
antoniogm

asked on

Maximum/minimum values of int, double, long, etc....

I am often writing optimization routines that either start or are toggled off of extremum values of various datatypes. Are there any globally-defined max/min values for the various types (int, long...). For example, coming from Java, there exist things like Double.MAX_VALUE that start you off at the upper limit of double.

I realize of course I could look through a book, remember how many bits are in a long, and do the binary arithmetic, but the Java approach or something like it seems preferable.
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of antoniogm
antoniogm

ASKER

Thanks for the response.

However...
There seems to be no limit on doubles however. Wha'ts up with that?
Thanks for the response.

However...
There seems to be no limit on doubles however. Wha'ts up with that?
> There seems to be no limit on doubles however. Wha'ts up with that?

There is no limit on floats and doubles.  The IEEE 754 float and double encodings
can represent numbers in the range +/- Infinity (with limited precision).  
For more info, see the following:

http://www.psc.edu/general/software/packages/ieee/ieee.html

So that raises the corollary question: how do you express infinity?

Or is there no way to do so? Do doubles just wrap around when incremented beyond their max?
If you had followed the hyperlink I gave, it shows exactly how
infinity is expressed.  You will also notice that it doesn't "wrap" as
you expect.

Idid follow the link, and it gives precisely the information that my question stated I did not want to deal with. Knowing how infinity is represented bitwise in some IEEE document does precious little good when coding in C++. In any case, I'll take the answer as 'no', there is no way to compactly represent the maximal value of a double in C.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To answer the original question more specifically than I did before, yes, there are functions similar to the Java functions.  There is a function is_bounded in the numeric_limits template class that returns a bool that tells you whether the type has a bounded set of representable values.  It returns true for all predefined types.  If numeric_limits<x>::is_bounded() is true for a type x, then numeric_limits<x>::max() returns the largest finite value the type can store, and numeric_limits<x>::min() returns the lowest finite value for the type.  There is also another function is_signed(), and min() also works if both is_bounded() and is_signed() are false.

--efn
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: bobbit31 {http:#9659283} & efn {http:#9661227} & brettmjohnson {http:#9662220}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer