Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

single, double and precision

Tags:

delphi

I know that storing single value (or double) can not be very precise. so storing for example 125.12 can result in 125.1200074788. now in delphi their is some usefull function like samevalue or comparevalue that take an epsilon as param and say that 125.1200074788 or for exemple 125.1200087952 is equal.

but i often see in code stuff like : if aSingleVar = 0 then ... and this in fact as i see always work. why ? why storing for exemple 0 in a single var keep the exact value ?

like image 818
zeus Avatar asked Jan 21 '17 13:01

zeus


People also ask

What is double precision example?

The word double derives from the fact that a double-precision number uses twice as many bits as a regular floating-point number. For example, if a single-precision number requires 32 bits, its double-precision counterpart will be 64 bits long.

What does precision mean in floating-point?

In a 32-bit system, 23 digits after the decimal point can be stored. Precision defines how many bits will be occupied in memory to store the number. The more bits are made available, the more digits after the decimal point can be stored before rounding occurs.

What is single precision accuracy?

Single precision floats have (recall) only 24 bits of precision. This is the equivalent of 7 to 8 decimal digits. SPIM should have printed -8.3199999 to the window. The 7 or 8 decimal digits of precision is much worse than most electronic calculators.

Is single precision faster than double precision?

Single precision on GPU can be 3 times, 8 times, 24 times, or 32 times faster than double precision, depending on the NVIDIA GPU model.


1 Answers

Only values that are in form m*2^e, where m and e are integers can be stored in a floating point variable (not all of them though, it depends on precision). 0 has this form, and 125.12 does not, as it equals 3128/25, and 1/25 is not an integer power of 2.

Comparing 125.12 to a single (or double) precision variable will most probably return always False, because a literal 125.12 will be treated as an extended precision number, and no single (or double) precision number would have such a value.

like image 57
mik Avatar answered Oct 04 '22 15:10

mik