math module broken?

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Sat Jul 24 15:35:04 EDT 2004


Peter Otten wrote:

> Roel Schroeven wrote:
> 
> 
>>When the numbers get larger, floats start losing precision. If you
>>restrict the numbers to the range [0, 360[ before conversion to radians
>>(and hence to degrees), that problem doesn't exist.
> 
> 
>>>>(360**100 +0.0) % 360
> 
> 184.0
> 
> Rule of thumb: floats are always inaccurate. % may only help when you are
> dealing with large integers denoting an angle in degrees - an unlikely
> scenario methinks.

Ok, you're right, I only considered the case where the input is 
specified in degrees.

Anyway, when dealing with angles it's in most cases very well possible 
to keep the values small by doing % 360 or % (2*pi) in all relevant 
operations on the angles.

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Python-list mailing list