minimum double value in C/C++


Question

Is there a standard and/or portable way to represent the smallest negative value (e.g. to use negative infinity) in a C(++) program?

DBL_MIN in float.h is the smallest positive number.

1
76
7/20/2009 1:23:51 PM

Accepted Answer

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

118
3/6/2011 11:59:57 PM

Floating point numbers (IEEE 754) are symmetrical, so if you can represent the greatest value (DBL_MAX or numeric_limits<double>::max()), just prepend a minus sign.

And then is the cool way:

double f;
(*((long long*)&f))= ~(1LL<<52);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon