### float, double and long double ranges ?

Hi guys

Does anyone knows the type number ranges of

float
double
long double

 ``123456789`` ``````#include #include int main() { std::cout << FLT_MIN << '\t' << FLT_MAX << '\n'; std::cout << DBL_MIN << '\t' << DBL_MAX << '\n'; std::cout << LDBL_MIN << '\t' << LDBL_MAX << '\n'; }``````

In VS 2019:
 ```1.17549e-38 3.40282e+38 2.22507e-308 1.79769e+308 2.22507e-308 1.79769e+308```
Floating point numbers are represented as a sum of a short sequence of powers of two, so relative error increases with the magnitude of the value. So this isn't particularly useful information because the ranges are enormous, and at the "edges" quantization error is so large as to make manipulating such values difficult.

Anyway the range of long double in particular varies between machines. To get it for your computer, run this program:
 ``1234567891011121314151617181920212223`` ``````#include #include #include int main() { #define O(t) \ do \ { \ auto const min = std::numeric_limits::min(); \ auto const max = std::numeric_limits::max(); \ \ std::cout << #t << ": minimum value x for which ::fpclassify(x) == FP_NORMAL: " \ << std::hexfloat << min << " = " << std::dec << min << '\n'; \ std::cout << #t << ": maximum value x for which ::fpclassify(x) == FP_NORMAL: " \ << std::hexfloat << max << " = " << std::scientific << max << "\n\n"; \ } while(false) \ /**/ O(float); O(double); O(long double); }``````

The number this program reports as the "minimum" is the positive normal value with the smallest absolute magnitude.

Last edited on
Thank you all

 ``12345678910`` `````` #include #include int main() { std::cout << FLT_MIN << '\t' << FLT_MAX << '\n'; std::cout << DBL_MIN << '\t' << DBL_MAX << '\n'; std::cout << LDBL_MIN << '\t' << LDBL_MAX << '\n'; }``````

This small program from Furry Guy is reporting this on my g++ compiler:

 ``` 1.17549e-38 3.40282e+38 2.22507e-308 1.79769e+308 3.3621e-4932 1.18973e+4932 ```
Last edited on
Topic archived. No new replies allowed.