please explain double

Started by
7 comments, last by Agony 19 years, 7 months ago
Can someone please explain what double does does it make extra room for more memory?
-----------------------------------Panic and anxiety Disorder HQ
Advertisement
double is a usually a double large version of the float datatype.

Thermo
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.
-- Single player is masturbation.
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?
yes I do thanks a lot =).
-----------------------------------Panic and anxiety Disorder HQ
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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Yeah, and what else?

Thermo
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
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke

This topic is closed to new replies.

Advertisement