degrees and radians.

Fernando Pérez fperez528 at yahoo.com
Mon May 6 17:15:50 EDT 2002


Raymond Hettinger wrote:

>> I am trying to get the math module to deal with degrees rather than
>> radians. (that it deals with radians for the angular functions like
>> sin() isn't mentioned in the docs, which was sort of an eyeopener :)  I
>> can't find any info on doing this. I can convert from-to degrees in the
>> code calling the function, but that's a bit clunky. Any pointers to an
>> FM to R? :)
> 
> There is a patch for adding degree/radian conversions.
> See http://www/python.org/sf/552452

Sorry to sound critical, but I doubt this will make it in (and I hope it 
doesn't). Reason: bloat. Yes, it's only two functions, but still, bloat is 
bloat. Plus, if you really need those conversions, it's less typing and more 
efficient (no function call) to simply use a multiplicative constant:

In [7]: to_rad = pi/180

In [8]: to_deg = 1/to_rad

In [9]: sin pi/4
------> sin (pi/4)
Out[9]: 0.70710678118654746

In [10]: sin 45*to_rad
-------> sin (45*to_rad)
Out[10]: 0.70710678118654746

In [11]: (pi/4)*to_deg
Out[11]: 45.0

I realize you have good intentions, but I truly don't think that in this case 
the benefits outweigh the cost. OTOH, one could add a comment in the 
docstrings to the effect of 'trig functions expect arguments in radians', 
since it does seem to cause confusion among newbies.

Cheers,

f.



More information about the Python-list mailing list