The limits for floating point types are defined in float.h not limits.h

Answer from Clifford 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?

🌐
TutorialsPoint
tutorialspoint.com › c_standard_library › float_h.htm
C Library - <float.h>
After executing the above code, we get the following result − · The maximum value of float = 3.4028234664e+38 The minimum value of float = 1.1754943508e-38 The number of digits in the number = 7.2996655210e-312
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › cpp › floating-limits
Floating Limits | Microsoft Learn
October 3, 2025 - Access to this page requires authorization. You can try changing directories. ... The following table lists the limits on the values of floating-point constants.
🌐
Quora
quora.com › Why-is-the-maximum-float-number-in-C-3-40282-cdot10-38
Why is the maximum float number in C++ 3.40282\cdot10^{38} ?
Answer (1 of 5): It isn’t. It IS that number (approximately, at least) if you are using a compiler for an IEEE-754[1] machine with single precision, because the 32-bit “single precision” float format has 1 bit for sign, 8 bits for exponent (biased by 127) and 23 bits for the mantissa, ...
🌐
The C Book
publications.gbdirect.co.uk › c_book › chapter9 › limits.html
The C Book — Limits
Two header files <float.h> and <limits.h> define several implementation specific limits. Table 9.1 gives the names declared, the allowable values, and a comment on what they mean. For example, the description of SHRT_MIN shows that in a given implementation the value must be less than or equal to −32767: this means that for maximum ...
🌐
cppreference.com
en.cppreference.com › c › types › limits
Numeric limits - cppreference.com
CHAR_BIT = 8 MB_LEN_MAX = 16 CHAR_MIN = -128 CHAR_MAX = +127 SCHAR_MIN = -128 SCHAR_MAX = +127 UCHAR_MAX = 255 SHRT_MIN = -32768 SHRT_MAX = +32767 USHRT_MAX = 65535 INT_MIN = -2147483648 INT_MAX = +2147483647 UINT_MAX = 4294967295 LONG_MIN = -9223372036854775808 LONG_MAX = +9223372036854775807 ...
🌐
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:
Find elsewhere
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.
🌐
Cplusplus
cplusplus.com › reference › cfloat
<cfloat> (float.h)
an exponent (also known as ... following way: value of floating-point = significand x baseexponent, with its corresponding sign. The following panel shows the name of the different values defined in this header and their minimal or maximal values for all implementations ...
🌐
Wikipedia
en.wikipedia.org › wiki › Single-precision_floating-point_format
Single-precision floating-point format - Wikipedia
July 31, 2026 - A floating-point variable can represent a wider range of numbers than a fixed-point variable of the same bit width at the cost of precision. 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 ...
Top answer
1 of 3
9

Use the same format you'd use for any other values of those types:

#include <float.h>
#include <stdio.h>
int main(void) {
    printf("FLT_MAX = %g\n", FLT_MAX);
    printf("DBL_MAX = %g\n", DBL_MAX);
    printf("LDBL_MAX = %Lg\n", LDBL_MAX);
}

Arguments of type float are promoted to double for variadic functions like printf, which is why you use the same format for both.

%f prints a floating-point value using decimal notation with no exponent, which will give you a very long string of (mostly insignificant) digits for very large values.

%e forces the use of an exponent.

%g uses either %f or %e, depending on the magnitude of the number being printed.

On my system, the above prints the following:

FLT_MAX = 3.40282e+38
DBL_MAX = 1.79769e+308
LDBL_MAX = 1.18973e+4932

As Eric Postpischil points out in a comment, the above prints only approximations of the values. You can print more digits by specifying a precision (the number of digits you'll need depends on the precision of the types); for example, you can replace %g by %.20g.

Or, if your implementation supports it, C99 added the ability to print floating-point values in hexadecimal with as much precision as necessary:

printf("FLT_MAX = %a\n", FLT_MAX);
printf("DBL_MAX = %a\n", DBL_MAX);
printf("LDBL_MAX = %La\n", LDBL_MAX);

But the result is not as easily human-readable as the usual decimal format:

FLT_MAX = 0x1.fffffep+127
DBL_MAX = 0x1.fffffffffffffp+1023
LDBL_MAX = 0xf.fffffffffffffffp+16380

(Note: main() is an obsolescent definition; use int main(void) instead.)

2 of 3
1

To print approximations of the maximums with enough digits to represent the actual values (the result of converting the printed value back to floating-point should be the original value), you can use:

#include <float.h>
#include <stdio.h>


int main(void)
{
    printf("%.*g\n", DECIMAL_DIG, FLT_MAX);
    printf("%.*g\n", DECIMAL_DIG, DBL_MAX);
    printf("%.*Lg\n", DECIMAL_DIG, LDBL_MAX);
    return 0;
}

In C 2011, you can use the more specific FLT_DECIMAL_DIG, DBL_DECIMAL_DIG, and LDBL_DECIMAL_DIG in place of DECIMAL_DIG.

To print the exact values, instead of approximations, you need to specify more precision. (int) (log10(x)+1) digits should be enough.

Approximations of the minimums and the epsilons can be printed with sufficient accuracy in the same way. However, calculating the numbers of digits needed for exact values may be more complicated than for the maximums. (Technically, it may be impossible in exotic C implementations. E.g., a base-three floating-point system would have a minimum not representable in any finite number of decimal digits. I am not aware of any such implementations in use.)

🌐
cpprefjp
cpprefjp.github.io › reference › cfloat › flt_max.html
FLT_MAX - cpprefjp C++日本語リファレンス
<cfloat> #define FLT_MAX implementation-defined · float の最大の有限値を表すマクロ。 以下の式で表される。 · $$ (1-b^{-p})b^{e_{\rm max}} $$ ここで、$b$ は指数表現の基数(FLT_RADIX)、$p$ は精度(基数 $b$ での仮数部の桁数、FLT_MANT_DIG...
🌐
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
🌐
Cplusplus
cplusplus.com › forum › general › 67783
Maximum whole number a float can represe - C++ Forum
April 7, 2012 - ... @JLBorges: I'm a little confused by the math you did. The Mantissa is the significant bits, not the exponent. If the exponent is 8 bits, the maximum range would be from 2^-126 - 2^127 (Times the value of 1.mantissa), with 00 given the value of 0, and FF the value infinity.
🌐
University of Hawaii
www2.hawaii.edu › ~walbritt › ics212 › examples › maximum.c
maximum.c
//display maximum values for integers (%i or %d) printf("char max = %i\n", CHARMAX); printf("short max = %i\n", SHRTMAX); printf("int max = %i\n", INTMAX); printf("long max = %li\n\n", LONGMAX); //use %li for long int · //display maximum values for floating-points printf("float max = %e\n", FLTMAX...
🌐
LabEx
labex.io › tutorials › java-how-to-use-the-float-max-method-to-find-the-maximum-of-two-float-values-414166
How to use the Float max method to find the maximum of two float values | LabEx
The syntax for using the Float.max() method is as follows: ... Here, a and b are the two float values to be compared, and the method returns the greater of the two values.
🌐
Processing
processing.org › reference › max_
max() / Reference / Processing.org
Copy · int a = max(5, 9); // Sets 'a' to 9 int b = max(-4, -12); // Sets 'b' to -4 float c = max(12.3, 230.24); // Sets 'c' to 230.24 · max(a, b) max(a, b, c) max(list) a(int, float)first number to compare · b(int, float)second number to compare · c(int, float)third number to compare ·
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-language › type-float
Type float | Microsoft Learn
The mantissa represents a number between 1.0 and 2.0. Since the high-order bit of the mantissa is always 1, it is not stored in the number. This representation gives a range of approximately 3.4E-38 to 3.4E+38 for type float. You can declare ...