-DBL_MAX in ANSI C, which is defined in float.h.

Answer from dfa on Stack Overflow
🌐
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:...
Discussions

c - Minimum of two floating-point numbers - Code Review Stack Exchange
I'm learning C and I just had the exercise to write a function that checks for the lower one of two floating-points. So I thought, I either could use pointer and also return the pointer of the lower value - otherwise, I simply could use the values and return the lower value. double* pointer_min_v... More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
September 2, 2021
Why don't float/double have a max & min value like 'int' or 'char'?
Dont use tutorials point. Its bad: reason www.learncpp.com is the best free tutorial out there. It covers everything from the absolute basics to advanced topics. It follows modern and best practice guidelines. www.cppreference.com is the best language reference out there. Stay away from cplusplus.com ( reason ), w3schools ( reason ), geeks-for-geeks ( reason ) Programiz( reason ) Tutorialspoint (), educba.com ( reason ) and thinkcpp ( reason ) Most youtube tutorials are of low quality, I would recommend to stay away from them as well. A notable exception are the CppCon Back to Basics videos. They are good, topic oriented and in depth explanations. However, they assume that you have some knowledge languages basic features and syntax and as such arent a good entry point into the language. As a tutorial www.learncpp.com is just better than any other resource. Written by u/IyeOnline . This may get updates over time if something changes or I write more scathing reviews of other tutorials :) . Feel free to copy this macro, but please copy it with this footer and the link to the original. https://www.reddit.com/user/IyeOnline/comments/10a34s2/the_c_learning_suggestion_macro/ More on reddit.com
🌐 r/cpp_questions
12
8
July 17, 2023
Just something I noticed with DOUBLE_MIN - GameDev.net Forums
I was just testing the how many decimal places a double is accurate up to when doing calculations, and I noticed i was getting results that were smaller than DBL_MIN. More on gamedev.net
🌐 gamedev.net
June 7, 2013
MIN and MAX in C - Stack Overflow
It was a terrible idea, but it also didn't even work, because the MAX he was using had the double evaluation problem, so he ended up with a different random number than the one that was initially evaluated. 2014-08-12T17:15:10.593Z+00:00 ... @Soumen For example, if you call MIN(x++, y++) the ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Cplusplus
cplusplus.com › forum › general › 53760
smallest double value greater zero - C++ Forum
October 30, 2011 - now my question is: what is the difference between min() and denorm_min() and why does not my code match any of these two? i looked up the doc here, but i dont understand it. ... You're packing your int array back to front. 000000001 00000000 -> 2.122e-314 000000000 00000001 -> 4.94066e-324 swapping your code to 1 and then 0, rather than vice versa... should do the trick! Andy Double precision floating-point format http://en.wikipedia.org/wiki/Double_precision Endianness http://en.wikipedia.org/wiki/Endianness
🌐
cppreference.com
en.cppreference.com › cpp › types › numeric_limits › min
std::numeric_limits<T>::min - cppreference.com
bool ( 1 bytes): 0 char ( 1 bytes): ... 0x8000000000000000 std::size_t ( 8 bytes): 0 float ( 4 bytes): 1.17549e-38 or 0x1p-126 double ( 8 bytes): 2.22507e-308 or 0x1p-1022 long double (16 bytes): 3.3621e-4932 or 0x8p-16385...
🌐
Dirask
dirask.com › posts › C-minimum-and-maximum-double-value-pYemwp
C++ - minimum and maximum double value
#include <limits> #include <iostream> using namespace std; int main() { double min = numeric_limits<double>::min(); // minimum positive value double max = numeric_limits<double>::max(); // maximum positive value double lowest = std::numeric...
🌐
The C Book
publications.gbdirect.co.uk › c_book › chapter9 › limits.html
The C Book — 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 portability a program cannot rely on short variables being able to hold values more negative than −32767.
🌐
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 - You need to know the largest or smallest representable value for your platform for a numeric type, such as an int or double. Use the numeric_limits class template in the <limits> header to get, among other things, the largest and smallest possible values for a numeric type (see Example 3-9). Example 3-9. Getting numeric limits · #include <iostream> #include <limits> using namespace std; template<typename T> void showMinMax() { cout << "min: " << numeric_limits<T>::min() << endl; cout << "max: " << numeric_limits<T>::max() << endl; cout << endl; } int main() { cout << "short:" << endl; showMin
Authors: D. Ryan StephensChristopher DigginsJonathan TurkanisJeff Cogswell
Published: 2005
Pages: 594
Top answer
1 of 4
16

Versatility

The pointer version is less versatile.

If the two values come from expressions like in min_value(x + 13, 2 * y), you can't use the pointer version, as neither x + 13 nor 2 * y exist as pointable memory locations, only as temporary values.

Surprises

The pointer version might give surprising results in the long run.

If now first is lower than second, the function will return a pointer to first. If you later change the content of the first variable, the value of the result changes as well.

If first and second are local variables declared inside a function foo(), and you happen to return the pointer_min_value() result (the pointer), then, after leaving foo(), the variables no longer exist, and your result points to garbage memory.

2 of 4
10

Some beautifying

I think first < second ? first : second is a tiny bit more readable. First comes first.

Double problems

Floating points are tricky. What will happen if one of doubles will be NaN? Of course, you can always say that the function assumes both values are valid, but you should consider this too.

Pointer problems

Pointers are also tricky. pointer_min_value(NULL, NULL) will cause UB. Once again, adding a comment "no NULLs allowed" is ok - but neglecting this possibility isn't.

Making sure the values, passed by pointers, won't change

You can add const modifier to arguments and returning value to do this, if you mean this.

Performance considerations

Passing a huge argument by value can be a bad idea; but doubles are only 8 bytes - like pointers on 86x64 architecture; pointers on 86x32 are 4 bytes, so you can save 8 bytes of stack space with pointer_min_value. But who cares with modern RAM sizes?

On the other hand, dereferencing pointers isn't free, so calc_min_value will be a bit faster, but who cares with modern CPU/RAM speeds and cache sizes?

Chief difference

The only thing pointer_min_value does that calc_min_value doesn't - it returns a pointer. Why is this important? Because you can change the returned value!

*pointer_min_value(&first, &second) = 0.0;

changes lesser one to 0.0. That's the greatest difference.

Find elsewhere
🌐
Reddit
reddit.com › r/cpp_questions › why don't float/double have a max & min value like 'int' or 'char'?
r/cpp_questions on Reddit: Why don't float/double have a max & min value like 'int' or 'char'?
July 17, 2023 -

source: https://www.tutorialspoint.com/cplusplus/cpp_data_types.htm#

There's no data shown for the limits floats and doubles have.

However, 'int' is -2147483648 to 2147483647 and 'char' is 0 to 255

🌐
GeeksforGeeks
geeksforgeeks.org › c++ › stdnumeric_limitsmax-and-stdnumeric_limitsmin-in-c
std::numeric_limits::max() and std::numeric_limits::min() in C++ - GeeksforGeeks
July 23, 2025 - bool: 1 char: 127 unsigned char: ... size_t: 18446744073709551615 · The std::numeric_limits<T>::min() function is used to get the minimum finite value representable by the numeric type T....
🌐
Medium
medium.com › @pauljlucas › a-generic-min-function-in-c-9706edb594ad
A Generic min Function in C. Introduction | by Paul J. Lucas | Medium
July 5, 2026 - You could use min_ld to handle both float and double, but long double is typically less performant than either, so casting all floating point values to long double isn’t a good idea.
🌐
GameDev.net
gamedev.net › home › forums › programming › general and gameplay programming › just something i noticed with double_min
Just something I noticed with DOUBLE_MIN - GameDev.net Forums
June 7, 2013 - However, it is not the smallest positive number representable as a floating point number, only the smallest normalized floating point number. Smaller numbers can be expressed in denormalized form, albeit at a loss of significance.
🌐
cppreference.com
en.cppreference.com › c › types › limits
Numeric limits - cppreference.com
#include <limits.h> #include <stdint.h> #include <stdio.h> int main(void) { printf("CHAR_BIT = %d\n", CHAR_BIT); printf("MB_LEN_MAX = %d\n\n", MB_LEN_MAX); printf("CHAR_MIN = %+d\n", CHAR_MIN); printf("CHAR_MAX = %+d\n", CHAR_MAX); printf("SCHAR_MIN = %+d\n", SCHAR_MIN); printf("SCHAR_MAX = %+d\n", SCHAR_MAX); printf("UCHAR_MAX = %u\n\n", UCHAR_MAX); printf("SHRT_MIN = %+d\n", SHRT_MIN); printf("SHRT_MAX = %+d\n", SHRT_MAX); printf("USHRT_MAX = %u\n\n", USHRT_MAX); printf("INT_MIN = %+d\n", INT_MIN); printf("INT_MAX = %+d\n", INT_MAX); printf("UINT_MAX = %u\n\n", UINT_MAX); printf("LONG_MIN =
Top answer
1 of 16
549

Where are MIN and MAX defined in C, if at all?

They aren't.

What is the best way to implement these, as generically and type safe as possible (compiler extensions/builtins for mainstream compilers preferred).

As functions. I wouldn't use macros like #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)), especially if you plan to deploy your code. Either write your own, use something like standard fmax or fmin, or fix the macro using GCC's typeof (you get typesafety bonus too) in a GCC statement expression:

 #define max(a,b) \
   ({ __typeof__ (a) _a = (a); \
       __typeof__ (b) _b = (b); \
     _a > _b ? _a : _b; })

Everyone says "oh I know about double evaluation, it's no problem" and a few months down the road, you'll be debugging the silliest problems for hours on end.

Note the use of __typeof__ instead of typeof:

If you are writing a header file that must work when included in ISO C programs, write __typeof__ instead of typeof.

2 of 16
131

It's also provided in the GNU libc (Linux) and FreeBSD versions of sys/param.h, and has the definition provided by dreamlax.


On Debian:

$ uname -sr
Linux 2.6.11

$ cat /etc/debian_version
5.0.2

$ egrep 'MIN\(|MAX\(' /usr/include/sys/param.h
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

$ head -n 2 /usr/include/sys/param.h | grep GNU
This file is part of the GNU C Library.

On FreeBSD:

$ uname -sr
FreeBSD 5.5-STABLE

$ egrep 'MIN\(|MAX\(' /usr/include/sys/param.h
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

The source repositories are here:

  • GNU C Library
  • FreeBSD
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 › forum › beginner › 50309
Smallest double from array - C++ Forum
I think you need another variable to keep track of the index. Set min to the first element in the array and then check everything else against it. Also shouldn't min be an int rather than a double, since that's the array type?
🌐
Google Groups
groups.google.com › a › isocpp.org › g › std-discussion › c › oanRzcpydiY
std::min, Cpp17LessThanComparable, doubles and NaN again.
Some people (me included) follow a, say, more theoretical approach and understand S as the set of all possible double values. We deduce that < is not a strict weak ordering on this set and thus, double is not Cpp17LessThanComparable. For us, instantiating std::min with T = double is UB, in particular, std::min(0.0, 1.0) is undefined.
🌐
Apache
db.apache.org › derby › docs › 10.1 › ref › rrefsqljdoubleprecision.html
DOUBLE PRECISION
The DOUBLE PRECISION data type provides 8-byte storage for numbers using IEEE floating-point notation.