please explain double
in c/c++, double is a very high precision floating point number. If you need many, many decimal places of accuracy, or expect obscene levels of magnitude, use double. Otherwise, use float. Common n00b error is to assume they always need double. You usually don't.
And if you really have to ask this here, you need to do a lot of reading before you write another line.
And if you really have to ask this here, you need to do a lot of reading before you write another line.
Quote:Original post by Pxtl
Common n00b error is to assume they always need double. You usually don't.
What is wrong with using double?
Common n00b error is to assume they always need optimization. You usually don't.
Thermo
A float is 4 bytes, a double is 8 bytes. That's twice as much room for precision (and twice as much memory).
A float loses it's precision when trying to deal with larger numbers, because it starts to round and widdle away (called truncating) on it's decimals to make room for the more significant whole numbers on the left.
A number like 0.1934818098 will not be a problem for a float. However, a value like 139401834.5919183498 will, because to make room for the 139401834 on the left, it has to start rounding and truncating the values to the right, so you might end up with something like this: 139401834.591918. You've lost 4 numbers of precision, which will affect all future calculations with this number.
Do you understand now?
A float loses it's precision when trying to deal with larger numbers, because it starts to round and widdle away (called truncating) on it's decimals to make room for the more significant whole numbers on the left.
A number like 0.1934818098 will not be a problem for a float. However, a value like 139401834.5919183498 will, because to make room for the 139401834 on the left, it has to start rounding and truncating the values to the right, so you might end up with something like this: 139401834.591918. You've lost 4 numbers of precision, which will affect all future calculations with this number.
Do you understand now?
Quote:Original post by Konfusius
What is wrong with using double?
When used as function parameters, floats will fit in a register, doubles don't.
Here is a page from MSDN with interesting numbers on it: Numerical Limits.
The most important ones are these:
FLT_DIG = 6
DBL_DIG = 15
The most important ones are these:
FLT_DIG = 6
DBL_DIG = 15
Quote:From MSDN
Number of digits, q, such that a floating-point number with q decimal digits can be rounded into a floating-point representation and back without loss of precision.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement