In experiments with the addition of 3.3 for 2,000,000,000 times the results:
Summation time in s: 2.82 summed value: 6.71089e+07 // float Summation time in s: 2.78585 summed value: 6.6e+09 // double Summation time in s: 2.76812 summed value: 6.6e+09 // long double
So double is faster and the default in C and C ++. It is more portable and is used by default in all library functions of C and C ++. Alos double has significantly higher accuracy than floating.
Even Stroustrup recommends a double float:
“The exact meaning of one-, two- and extended accuracy is determined by the implementation. Choosing the right accuracy for a problem where the choice matters requires a significant understanding of floating point calculations. If you don’t have this understanding, get tips, take time to learn, or use double and hope for the best. "
Perhaps the only case where you should use float instead of double is 64-bit hardware with modern gcc. Since float is less; double is 8 bytes, and float is 4 bytes.
Akash Agrawal Mar 18 '12 at 18:20 2012-03-18 18:20
source share