The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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.

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.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialHowever...

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

However...

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

Or is there no way to do so? Do doubles just wrap around when incremented beyond their max?

infinity is expressed. You will also notice that it doesn't "wrap" as

you expect.

For details, see:

http://www.dinkumware.com/manuals/reader.aspx?b=p/&h=limits2.html

The IEEE standard for floating point numbers does have special values for positive infinity, negative infinity, and "not a number," but the number of different values it can represent is certainly finite.

--efn

> 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.

Actually, it has everything to do with coding in C++, since that is

how C/C++ represents floating point numbers. I'm still not sure

what you are looking for. I think what you want is in math.h.

To set a float to infinity:

float f = INFINITY;

To test if float is infinity:

if (isinf(f)) ...

To test if float is finite:

if (isfinite(f)) ...

To test if float is NaN (Not a Number)

if (isnan(f)) ...

To set a float to NaN:

float f = NAN;

--efn

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

C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

{CHAR_BIT}

Number of bits in a type char.

[CX] Value: 8

{CHAR_MAX}

Maximum value of type char.

Value: {UCHAR_MAX} or {SCHAR_MAX}

{CHAR_MIN}

Minimum value of type char.

Value: {SCHAR_MIN} or 0

{INT_MAX}

Maximum value of an int.

Minimum Acceptable Value: 2 147 483 647

{LONG_BIT}

[XSI]

Number of bits in a long.

Minimum Acceptable Value: 32

{LONG_MAX}

Maximum value of a long.

Minimum Acceptable Value: +2 147 483 647

{MB_LEN_MAX}

Maximum number of bytes in a character, for any supported locale.

Minimum Acceptable Value: 1

{SCHAR_MAX}

Maximum value of type signed char.

[CX] Value: +127

{SHRT_MAX}

Maximum value of type short.

Minimum Acceptable Value: +32 767

{SSIZE_MAX}

Maximum value of an object of type ssize_t.

Minimum Acceptable Value: {_POSIX_SSIZE_MAX}

{UCHAR_MAX}

Maximum value of type unsigned char.

[CX] Value: 255

{UINT_MAX}

Maximum value of type unsigned.

Minimum Acceptable Value: 4 294 967 295

{ULONG_MAX}

Maximum value of type unsigned long.

Minimum Acceptable Value: 4 294 967 295

{USHRT_MAX}

Maximum value for a type unsigned short.

Minimum Acceptable Value: 65 535

{WORD_BIT}

[XSI]

Number of bits in a word or type int.

Minimum Acceptable Value: 16

{INT_MIN}

Minimum value of type int.

Maximum Acceptable Value: -2 147 483 647

{LONG_MIN}

Minimum value of type long.

Maximum Acceptable Value: -2 147 483 647

{SCHAR_MIN}

Minimum value of type signed char.

[CX] Value: -128

{SHRT_MIN}

Minimum value of type short.

Maximum Acceptable Value: -32 767

{LLONG_MIN}

Minimum value of type long long.

Maximum Acceptable Value: -9223372036854775807

{LLONG_MAX}

Maximum value of type long long.

Minimum Acceptable Value: +9223372036854775807

{ULLONG_MAX}

Maximum value of type unsigned long long.

Minimum Acceptable Value: 18446744073709551615

for more: http://www.opengroup.org/onlinepubs/007904975/basedefs/limits.h.html