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)

Answer from Random832 on Stack Overflow
🌐
Reddit
reddit.com › r/c_programming › confused about the max limit we can store for float and double
r/C_Programming on Reddit: confused about the max limit we can store for float and double
February 1, 2024 -

Just started learning C. so forigve me if this is a dumb question.

For int and long, the maximum number we can assign them is 2^32 and 2^64 respectively. how about for float and double? I know that double has higher precision of about 15 decimal points while float is 7.

i also know that float is 32 bit while double is 64 bit. So does that mean the highest we can store them (2^32)and (2^64) but with decimal points in between their numbers? i aslo learnt that these data type cant have unsigned value so does that value doubles?

Discussions

Maximum value of a double
According to the LR the maximum value of a double is: Numerical limits The maximum value of a Double is: ±1.79769313486231570814527423731704357e+308 The minimum value towards zero is: ±4.94065645841246544176568792868221372e-324 So, what am I doing wrong in this example since what I get is ... More on forum.xojo.com
🌐 forum.xojo.com
18
0
May 4, 2021
float and double - C++ Forum
I understood that integer can have numbers from 0 to 65536. but didn't understand the limitations of the float and double. ... Minimum value for a float is 1.175494351 E – 38 (if you're not familiar with "E" it means "*10^"). Max float is 3.402823466 E + 38. More on cplusplus.com
🌐 cplusplus.com
October 31, 2012
variables - What are the actual min/max values for float and double (C++) - Stack Overflow
For a floating-point type T, here ... called double in this answer. These are in decreasing order: std::numeric_limits::infinity() is the largest representable value, if T supports infinity. It is, of course, infinity. Whether the type T supports infinity is indicated by std::numeric_limits::has_infinity. std::numeric_limits::max() is the largest ... More on stackoverflow.com
🌐 stackoverflow.com
Is the maximum supported digits for a double type in c is 15 digits or more
In your code, the variable a is assigned the value 12345678901234567, which is a 17-bit number. Due to the precision limitation of double, it is difficult to accurately represent such a large number. Therefore, rounding or approximation occurs on output, causing the last digit to become 8 instead of the original 7. ... A double is stored in base 2 not decimal. It’s stored in 64 bits. The mantissa is 52 bits, or max ... More on learn.microsoft.com
🌐 learn.microsoft.com
2
0
May 28, 2023
🌐
O'Reilly
oreilly.com › library › view › c-cookbook › 0596007612 › ch03s08.html
3.7. Getting the Minimum and Maximum Values for a Numeric Type - C++ Cookbook [Book]
November 8, 2005 - Here’s what I get on Windows XP using Visual C++ 7.1: short: min: -32768 max: 32767 int: min: -2147483648 max: 2147483647 long: min: -2147483648 max: 2147483647 float: min: 1.17549e-038 max: 3.40282e+038 double: min: 2.22507e-308 max: 1.79769e+308 ...
Authors: D. Ryan StephensChristopher DigginsJonathan TurkanisJeff Cogswell
Published: 2005
Pages: 594
🌐
Xojo Programming Forum
forum.xojo.com › general
Maximum value of a double - General - Xojo Programming Forum
May 4, 2021 - According to the LR the maximum value of a double is: Numerical limits The maximum value of a Double is: ±1.79769313486231570814527423731704357e+308 The minimum value towards zero is: ±4.94065645841246544176568792868…
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 463134 › what-is-the-max-value-of-a-double
c++ - What is the Max value of a double? [SOLVED] | DaniWeb
September 13, 2013 - Avoid integer division; ensure operands are double. If you need the C macro for completeness, see DBL_MAX in <cfloat> on cppreference: cfloat. The problem with using the maximum value of a double is that you will most certainly lose all meaningful value in your samples array.
🌐
cppreference.com
en.cppreference.com › cpp › types › numeric_limits › max
std::numeric_limits<T>::max - cppreference.com
#include <boost/type_index.hpp> ...alue_of<std::size_t>(); print_max_value_of<char>(); print_max_value_of<char16_t>(); print_max_value_of<wchar_t>(); print_max_value_of<float>(); print_max_value_of<double>(); print_max_value_of<long double>(); }...
🌐
Cmu
jitsi.cmu.edu.jm › home › c++: double max value trick & pitfalls
C++: Double Max Value Trick & Pitfalls
March 16, 2025 - The largest representable positive finite number of the `double` floating-point type, as defined by the IEEE 754 standard and implemented in C++, represents an upper limit on the magnitude of values that can be stored in this data type without resulting in overflow. This value can be accessed through the `std::numeric_limits::max()` function in the “ header.
Find elsewhere
🌐
Quora
quora.com › What-are-the-maximum-and-minimum-value-of-double-float-variables-in-C
What are the maximum and minimum value of double float variables in C++? - Quora
Answer: In C++ you can find the answer to your question n the header files. Some of the limits are dependent on implementation which means the standard doesn’t say what the values are. You have to look them up ni a header file: climits for integral types cfloat for floating point types. https:...
🌐
Quora
quora.com › What-is-the-largest-integer-a-long-double-can-hold-assuming-I-need-to-include-both-negative-0-and-positive-in-C
What is the largest integer a long double can hold (assuming I need to include both negative, 0, and positive) in C? - Quora
Answer (1 of 3): It depends on the compiler and the machine. You should check the documentation for your software. According to the Pelles C compiler for Windows, a long double is not different from a double and the maximum representable finite value for type double is given by the macro DBL_MAX...
🌐
Cplusplus
cplusplus.com › forum › beginner › 83526
float and double - C++ Forum
October 31, 2012 - Min double is 2.2250738585072014 E – 308 and max double is 1.7976931348623158 E + 308. If you're not understanding these limitations, keep in mind that the computer is storing them in binary. The number and all the decimal places take up a certain amount of memory in binary.
Top answer
1 of 4
26

Alright. Using what I learned from here (thanks everyone) and the other parts of the web I wrote a neat little summary of the two just in case I run into another issue like this.

In C++ there are two ways to represent/store decimal values.

Floats and Doubles

A float can store values from:

  • -340282346638528859811704183484516925440.0000000000000000 Float lowest
  • 340282346638528859811704183484516925440.0000000000000000 Float max

A double can store values from:

  • -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000000000000000 Double lowest

  • 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000000000000000 Double max

Float's precision allows it to store a value of up to 9 digits (7 real digits, +2 from decimal to binary conversion)

Double, like the name suggests can store twice as much precision as a float. It can store up to 17 digits. (15 real digits, +2 from decimal to binary conversion)

e.g.

     float x = 1.426;
     double y = 8.739437;

Decimals & Math

Due to a float being able to carry 7 real decimals, and a double being able to carry 15 real decimals, to print them out when performing calculations a proper method must be used.

e.g

include

typedef std::numeric_limits<double> dbl; 
cout.precision(dbl::max_digits10-2); // sets the precision to the *proper* amount of digits.
cout << dbl::max_digits10 <<endl; // prints 17.
double x = 12345678.312; 
double a = 12345678.244; 
// these calculations won't perform correctly be printed correctly without setting the precision.


cout << endl << x+a <<endl;

example 2:

typedef std::numeric_limits< float> flt;
cout.precision(flt::max_digits10-2);
cout << flt::max_digits10 <<endl;
float x =  54.122111;
float a =  11.323111;

cout << endl << x+a <<endl; /* without setting precison this outputs a different value, as well as making sure we're *limited* to 7 digits. If we were to enter another digit before the decimal point, the digits on the right would be one less, as there can only be 7. Doubles work in the same way */

Roughly how accurate is this description? Can it be used as a standard when confused?

2 of 4
15

The std::numerics_limits class in the <limits> header provides information about the characteristics of numeric types.

For a floating-point type T, here are the greatest and least values representable in the type, in various senses of “greatest” and “least.” I also include the values for the common IEEE 754 64-bit binary type, which is called double in this answer. These are in decreasing order:

  • std::numeric_limits<T>::infinity() is the largest representable value, if T supports infinity. It is, of course, infinity. Whether the type T supports infinity is indicated by std::numeric_limits<T>::has_infinity.

  • std::numeric_limits<T>::max() is the largest finite value. For double, this is 21024−2971, approximately 1.79769•10308.

  • std::numeric_limits<T>::min() is the smallest positive normal value. Floating-point formats often have an interval where the exponent cannot get any smaller, but the significand (fraction portion of the number) is allowed to get smaller until it reaches zero. This comes at the expense of precision but has some desirable mathematical-computing properties. min() is the point where this precision loss starts. For double, this is 2−1022, approximately 2.22507•10−308.

  • std::numeric_limits<T>::denorm_min() is the smallest positive value. In types which have subnormal values, it is subnormal. Otherwise, it equals std::numeric_limits<T>::min(). For double, this is 2−1074, approximately 4.94066•10−324.

  • std::numeric_limits<T>::lowest() is the least finite value. It is usually a negative number large in magnitude. For double, this is −(21024−2971), approximately −1.79769•10308.

  • If std::numeric_limits<T>::has_infinity and std::numeric_limits<T>::is_signed are true, then -std::numeric_limits<T>::infinity() is the least value. It is, of course, negative infinity.

Another characteristic you may be interested in is:

  • std::numeric_limits<T>::digits10 is the greatest number of decimal digits such that converting any decimal number with that many digits to T and then converting back to the same number of decimal digits will yield the original number. For double, this is 15.
🌐
The C Book
publications.gbdirect.co.uk › c_book › chapter9 › limits.html
The C Book — Limits
For floating point numbers, the file <float.h> contains a similar set of minimum values. (It is assumed that where no minimum value is specified, there is either no minimum, or the value depends on another value.)
Top answer
1 of 2
1

Hi Debojit Acharjee,

The significand of the double type is approximately 15 to 17 decimal digits for most platforms. In most cases, a variable of type double can accurately represent 15 to 17 decimal digits. Numbers outside this range may lose precision or be rounded.

When I defined a 18 digits number, the result lost precision.

When using floating-point numbers, you should choose the appropriate data type according to your specific needs and precision requirements, and avoid using values beyond its representation range for calculations.

Regarding the double type, this documentation states:

Microsoft Specific The double type contains 64 bits: 1 for sign, 11 for the exponent, and 52 for the mantissa. Its range is +/-1.7E308 with at least 15 digits of precision.

You could also refer to this document for the float type.

Best regards,

Elya Yao


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

2 of 2
0

A double is stored in base 2 not decimal. It’s stored in 64 bits. The mantissa is 52 bits, or max 179769313486232 in decimal. The exponent is 11 bits or max of 2047 in decimal. The final bit is the sign bit.

See:

https://en.wikipedia.org/wiki/Computer_number_format#:~:text=an%2011%2Dbit%20binary%20exponent,gives%20the%20actual%20signed%20value

🌐
Educative
educative.io › answers › what-is-the-doublemaxvalue-in-c-sharp
What is the Double.MaxValue in C#?
The Double.MaxValue in C# is a Double field that represents the largest possible value of Double. It is constant and read-only.
🌐
cppreference.com
en.cppreference.com › cpp › types › numeric_limits › infinity
std::numeric_limits<T>::infinity - cppreference.com
In IEEE 754, the most common binary representation of floating-point numbers, the positive infinity is the value with all bits of the exponent set and all bits of the fraction cleared. ... #include <iostream> #include <limits> int main() { double max = std::numeric_limits<double>::max(); double inf = std::numeric_limits<double>::infinity(); if (inf > max) std::cout << inf << " is greater than " << max << '\n'; }
🌐
Arm
support.arm.com › documentation › dui0041 › c › ARM-Compiler-Reference › Limits-for-floating-point-numbers
ARM Software Development Toolkit Reference Guide
December 16, 2024 - The following tables give the characteristics, ranges, and limits for floating-point numbers as implemented in ARM C and C++. Note also:
🌐
Cplusplus
cplusplus.com › reference › limits › numeric_limits
std::numeric_limits
Provides information about the properties of arithmetic types (either integral or floating-point) in the specific platform for which the library compiles. This class template is specialized for every fundamental arithmetic type, with its members describing the properties of type T.