I know of LONG_MAX for intergers, but what is the identifer for the largest and smallest floats and which header file is it in ?
Printable View
I know of LONG_MAX for intergers, but what is the identifer for the largest and smallest floats and which header file is it in ?
i can't remember the name of the constant, but the header file is called 'limits.h' and if you browse through it the answer should be easy to find.
float
32 bits
1.18x10^-38 < |X| < 3.40x10^38 Scientific (7-digit) precision)
double
64 bits
2.23x10^-308 < |X| < 1.79x10^308 Scientific (15-digit precision)
long double
80 bits
3.37x10^-4932 < |X| < 1.18x10^4932 Financial (18-digit precision)
>but the header file is called 'limits.h'
float.h, or cfloat for new C++ headers.
>float
>32 bits
>1.18x10^-38 < |X| < 3.40x10^38 Scientific (7-digit) precision)
The size of float, double, and long double are implementation-defined.
-PreludeCode:#include <iostream>
#include <cfloat>
int main()
{
std::cout<< FLT_MAX <<'\n'<< DBL_MAX <<'\n'<< LDBL_MAX <<std::endl;
return 0;
}
I know 32-bit flaoting number representation.
Are the double and long double the same?
I think prelude is right, sizes are implementation defined. The values I gave will be probable.
I guess C++ standard will only goes as far as:
sizeof(double) <= sizeof(long double)
The other words, they may be or may not be equal.
On my machine, FLT_MAX is the same as yours, Davros: 3.40282e+38.
DBL_MAX = 1.79769e+308 and LDBL_MAX = 1.18973e+4932, again, on my machine.
A long double is an eensy bit larger. :D
-Skipper
Code:#undef max
#include <limits>
//To obtain the maximum values
std::numeric_limits<float>::max()
std::numeric_limits<double>::max()
std::numeric_limits<long double>::max()