What does a double precision variable mean?

Asked

Viewed 10,908 times

7

I would like to understand the meaning of a variable of double precision.

1 answer

5


Usually called double, is the variable that stores a number of floating point with space to indicate larger numbers, either in the whole part or in the decimal part. He is the "brother" of the type float which is the kind of simple precision. Generally the float occupies 4 bytes and the double takes 8 bytes. Some implementations take up to 10 bytes and up to 16 bytes, although in this case it is often called precision quadruple.

In fact variable is just a name for a storage location. Values have types. In static typing languages variables accept values of only one type according to code declaration.

Floating point types are often implemented by binary representation so that calculations are done quickly by processors. If the representation were decimal the calculation would not be natural for the processor and would take much longer. There is a disadvantage in this choice. There is no accuracy, so not all numbers can be represented that way. You can always represent a very close number, which is almost the same, but not exactly the same. It is not a problem for scientific calculations, but to represent money it does not serve. Money needs the exact amount. Never use float and double for money or other values that need accuracy.

So understand that accuracy and precision are different things. Accuracy has more to do with the ability to express larger numbers, more houses on the right or left. Precision is the degree of variation of the results of a measurement. Exactness, which refers to compliance with the actual value.

Floating point numbers are stored with a significant value multiplied by a fixed base elevated to a exponent, beyond the signal.

Simple precision:

Ponto flutuante precisão simples

Double precision:

Ponto flutuante precisão dupla

The more bits available the more the number can be accurate.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.