Just did this:
double val1=numeric_limits<double>::max();
cout.precision(70);
cout<<"\nVal1: "<<val1;
In Windows I start getting 0s after 17 digits(16 digits after decimal point). However in Linux, as I keep increasing the cout.precision(NUMBER), more and more digits keep showing and they are not zeros.
Also, running the following code shows '15' on both Windows and Linux. Windows system is 32 bits and Linux one is 64 bit if that makes any difference.
typedef std::numeric_limits< double > dl;
cout << "\tdigits (decimal):\t" << dl::digits10 << endl;
Can any one help with an explanation as to what is going on here? I thought number of precision digits will be same in Windows & Linux since sizeof(double) is 8 on both of them.
double has 15 decimal digits of precision.
Double precision numbers are accurate up to sixteen decimal places but after calculations have been done there may be some rounding errors to account for. In theory this should affect no more than the last significant digit but in practice it is safer to rely upon fewer decimal places.
Precision: 15 to 17 significant digits, depending on usage. The number of significant digits does not depend on the position of the decimal point. Representation: The values are stored in 8 bytes, using IEEE 754 Double Precision Binary Floating Point format.
The C++ double should have a floating-point precision of up to 15 digits as it contains a precision that is twice the precision of the float data type.
Once you get past the number of digits contained in a double, you're at the mercy of your compiler's library implementation. Different algorithms for converting from binary to decimal will result in different output. Neither can be more accurate than the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With