Oct 6, 2021 at 11:22pm UTC
Hi guys
Does anyone knows the type number ranges of
float
double
long double
Thanks in advance
Oct 7, 2021 at 12:08am UTC
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
#include <limits>
#include <iomanip>
int main()
{
#define O(t) \
do \
{ \
auto const min = std::numeric_limits<t>::min(); \
auto const max = std::numeric_limits<t>::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.
See also
std::numeric_limits<t>::lowest()
Last edited on Oct 7, 2021 at 12:10am UTC
Oct 7, 2021 at 8:21am UTC
Thank you all
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <cfloat>
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 Oct 7, 2021 at 8:22am UTC