Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get DOUBLE_MAX?

Tags:

c

double

AFAIK, C supports just a few data types:

int, float, double, char, void enum. 

I need to store a number that could reach into the high 10 digits. Since I'm getting a low 10 digit # from

INT_MAX

, I suppose I need a double.

<limits.h> doesn't have a DOUBLE_MAX. I found a DBL_MAX on the internet that said this is LEGACY and also appears to be C++. Is double what I need? Why is there no DOUBLE_MAX?

like image 963
P.Brian.Mackey Avatar asked Apr 29 '11 16:04

P.Brian.Mackey


People also ask

What is the largest number a double can hold?

Remarks. The value of this constant is positive 1.7976931348623157E+308.

Is there a double max value Java?

Double. MAX_VALUE is the maximum value a double can represent (somewhere around 1.7*10^308).

What is the max size of double in Java?

MAX_VALUE. A constant holding the largest positive finite value of type double , (2-2-52)·21023. It is equal to the hexadecimal floating-point literal 0x1.

What is float max?

A signed 32-bit integer variable has a maximum value of 231 − 1 = 2,147,483,647, whereas an IEEE 754 32-bit base-2 floating-point variable has a maximum value of (2 − 2−23) × 2127 ≈ 3.4028235 × 1038.


2 Answers

DBL_MAX is defined in <float.h>. Its availability in <limits.h> on unix is what is marked as "(LEGACY)".

(linking to the unix standard even though you have no unix tag since that's probably where you found the "LEGACY" notation, but much of what is shown there for float.h is also in the C standard back to C89)

like image 108
Random832 Avatar answered Sep 23 '22 10:09

Random832


You get the integer limits in <limits.h> or <climits>. Floating point characteristics are defined in <float.h> for C. In C++, the preferred version is usually std::numeric_limits<double>::max() (for which you #include <limits>).

As to your original question, if you want a larger integer type than long, you should probably consider long long. This isn't officially included in C++98 or C++03, but is part of C99 and C++11, so all reasonably current compilers support it.

like image 25
Jerry Coffin Avatar answered Sep 24 '22 10:09

Jerry Coffin