Skip to main content
GameDev.net gamedev.net
🔒 Locked

max value for DOUBLE ?

Started by xyuri May 10, 2006 at 2:16 AM 10 replies 219.3k views
Original Post
xyuri
xyuri
I have searched the web a bit but cant seem to find where in the standard set of libraries to find a declaration for the max value for the double primitive data type. I have also searched the library myself and cant find it ... it must be there right? Anyone know?
____Michael Dawson"IRC is just multiplayer notepad." - Reverend
Trap
Trap
+infinity is the max value

I'm not sure what the right way to create one is, you could try 1.0/0.0
mumpo
mumpo
I believe what you are looking for is this. It lists the minimum and maximum values a double can hold in C++ as -1.7*10^308 and 1.7*10^308, respectively.
Boder
Boder
The C++ standard usually doesn't require variables be a certain size, so IIRC a double doesn't have to be 8 bytes (but it probably will be[grin])

Maybe cfloat will be of use. Or maybe, if you need to represent infinity, you could try limits
simonjacoby
simonjacoby
EDIT: sorry, Boder was faster ;)

The values you are looking for are defined in float.h (float/double types) and limits.h (integer types). Just include them and use the constants, instead of hardcoding into your app.

Here's a snippet from float.h:

#define DBL_DIG 15 /* # of decimal digits of precision */
#define DBL_EPSILON 2.2204460492503131e-016 /* smallest such that 1.0+DBL_EPSILON != 1.0 */
#define DBL_MANT_DIG 53 /* # of bits in mantissa */
#define DBL_MAX 1.7976931348623158e+308 /* max value */
#define DBL_MAX_10_EXP 308 /* max decimal exponent */
#define DBL_MAX_EXP 1024 /* max binary exponent */
#define DBL_MIN 2.2250738585072014e-308 /* min positive value */
#define DBL_MIN_10_EXP (-307) /* min decimal exponent */
#define DBL_MIN_EXP (-1021) /* min binary exponent */
#define _DBL_RADIX 2 /* exponent radix */
#define _DBL_ROUNDS 1 /* addition rounding: near */

#define FLT_DIG 6 /* # of decimal digits of precision */
#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */
#define FLT_GUARD 0
#define FLT_MANT_DIG 24 /* # of bits in mantissa */
#define FLT_MAX 3.402823466e+38F /* max value */
#define FLT_MAX_10_EXP 38 /* max decimal exponent */
#define FLT_MAX_EXP 128 /* max binary exponent */
#define FLT_MIN 1.175494351e-38F /* min positive value */
#define FLT_MIN_10_EXP (-37) /* min decimal exponent */
#define FLT_MIN_EXP (-125) /* min binary exponent */
#define FLT_NORMALIZE 0
#define FLT_RADIX 2 /* exponent radix */
#define FLT_ROUNDS 1 /* addition rounding: near */

Cheers,
Simon
xyuri
xyuri
Well, the reason I am thinking about this is because with my app I allow the user to input a DOUBLE type number, but if I enter anything larger than around 200 it seems to treat the number wrongly ... I am under the assumtion that this is caused by the DOUBLE value looping back to 0? I thought the actual max value was larger than ~100 to ~200 ??
____Michael Dawson"IRC is just multiplayer notepad." - Reverend
Spoonbender
Spoonbender
Quote:
Well, the reason I am thinking about this is because with my app I allow the user to input a DOUBLE type number, but if I enter anything larger than around 200 it seems to treat the number wrongly ... I am under the assumtion that this is caused by the DOUBLE value looping back to 0? I thought the actual max value was larger than ~100 to ~200 ??

Quote:

#define DBL_MAX 1.7976931348623158e+308 /* max value */


That should answer your question... [wink]
Beer Hunter
Beer Hunter
If you need it, there's also std::numeric_limits::max() in the header.
Vendayan
Vendayan
Xyuri, it sounds like you're hitting a precision error. Keep in mind that even double floats can very very rarely ever be compared to one another for equality. This is because due to the fact that floats are only so precise, a few properties of mathmatics do not hold true for them.
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
Zahlman
Zahlman
Quote:
Original post by xyuri
Well, the reason I am thinking about this is because with my app I allow the user to input a DOUBLE type number, but if I enter anything larger than around 200 it seems to treat the number wrongly ... I am under the assumtion that this is caused by the DOUBLE value looping back to 0? I thought the actual max value was larger than ~100 to ~200 ??


Define "treat wrongly".
ItsDoh
ItsDoh
Incase you're not entirely clear on the notation being used, and since you asked if the limit was around 200 I'm guessing you may not be, the approximate limit as was stated is:

1.7976931348623158e+308


which is approximately:


179769313486231580000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000


But again as was stated, your precision isn't going to be dead on. Equalities on floats in general are almost useless.
mumpo
mumpo
Quote:
Original post by xyuri
Well, the reason I am thinking about this is because with my app I allow the user to input a DOUBLE type number, but if I enter anything larger than around 200 it seems to treat the number wrongly ... I am under the assumtion that this is caused by the DOUBLE value looping back to 0? I thought the actual max value was larger than ~100 to ~200 ??

You ought to post the code where you take the double input, and the code where you are not getting the expected results from working with the double.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.