[Tutor] [OT] Re: Floating Point Crazines

Steven D'Aprano steve at pearwood.info
Mon Jun 13 04:11:51 CEST 2011


Robert Sjoblom wrote:
>>> * Or you just get used to the fact that some numbers are not exact in
>>> floating point.
>> This got me thinking. How many decimal places do you need to
>> accurately, say, aim a laser somewhere in a 180 degree arc accurately
>> enough to hit a dime on the surface of the moon?
>>
>> Alan
> 
> In short: it's pretty much impossible.
[...]
> To bring it back on topic: could python handle these numbers reliably?

*Physically* impossible, not mathematically.

If you prefer, imagine putting a laser and a dime in deep space, far 
from any dust or atmosphere or gravitational distortion, so that we can 
assume perfectly Euclidean geometry. Put the dime some distance away, 
and aim the laser at the centre of it:


laser * --------------------------- + dime

Your margin of error in the aiming angle is given by the angle subtended 
by the dime. That is, you don't have to aim exactly at the centre (angle 
= 0 degrees), but at any angle between -a and +a degrees, whatever a 
happens to be. That angle a gives the precision needed.

(Strictly speaking, we should be talking about solid angles, steradians, 
rather than degrees. But for this thought experiment, the difference 
doesn't matter.)

Andre Walker-Loud has already given a back-of-the-envelope calculation 
which estimates that angle as about 1e-11, so the precision needed is 
about 12 decimal places.

Python's floats have 52 *binary* places of precision, or approximately 
15 *decimal* places. So even though we may not be able to physically 
build a machine capable of aiming a laser to a precision of 
0.00000000001 degrees, at least we can be comforted by the knowledge 
that a C double or a Python float is precise enough to handle the job.



-- 
Steven


More information about the Tutor mailing list