Erik2000 wrote in news:30****************@dbforums.com:
If someone defines a float and double in C++, does that say anything
about how many digits the number will hold at maximum and how many
places there will be after the decimal point?
Or is this open to interpretation?
The class template std::numeric_limits< Type >
defined in <limits> has a whole bunch of static members
that describe the properties of C++'s numeric types.
Here's an example:
#include <iostream>
#include <ostream>
#include <limits>
int main()
{
typedef std::numeric_limits< double > dl;
typedef std::numeric_limits< float > fl;
using namespace std;
cout << "double:\n";
cout << "\tdigits (bits):\t\t" << dl::digits << endl;
cout << "\tdigits (decimal):\t" << dl::digits10 << endl;
cout << endl;
cout << "float:\n";
cout << "\tdigits (bits):\t\t" << fl::digits << endl;
cout << "\tdigits (decimal):\t" << fl::digits10 << endl;
}
I get:
double:
digits (bits): 53
digits (decimal): 15
float:
digits (bits): 24
digits (decimal): 6
on my system.
HTH
Rob.
--
http://www.victim-prime.dsl.pipex.com/