degrees and radians.

Steve Holden sholden at holdenweb.com
Mon May 6 17:41:29 EDT 2002


"Fernando Pérez" <fperez528 at yahoo.com> wrote in message
news:ab6rvq$ka4$1 at peabody.colorado.edu...
> 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

Let's make that pi/180.0 so it works before the division unification takes
place, shall we?
>
> In [8]: to_deg = 1/to_rad
>
> In [9]: sin pi/4
> ------> sin (pi/4)

Similarly this should be pi/4.0

> 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.
>
But these would be maths newbies as well as Python newbies. The comment is a
good idea.

regards
 Steve
--

Steve Holden: http://www.holdenweb.com/ ; Python Web Programming:
http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list