math module broken?

Jon Wright jonathan.wright at gmail.com
Fri Jul 23 19:00:15 CEST 2004


Helmut Jarausch <jarausch at igpm.rwth-aachen.de> wrote in message 

> Both are "correct" if you know what you have been asking for.
> In standard mathematics the argument to a trigonometric function like
> sin, cos, tan, ...  is in radians (!)

There was some discussion about this recently over in
comp.lang.fortran, arising when someone queried sin/cos/tan etc for
very large angles (represented in floating point, eg: sin(1.0E18)).
Reduction (angle modulo 2pi) is considerably easier if you use a
*rational* unit for measuring angles, as the answer can remain exact
in terms of the particular number represented in floating point.
Without using an irrational number, exact representations of angles
can actually exist where you also have exact representations of sines
and cosines. With radians you can only represent zero exactly, and
below it seems not even that!

Can someone supply a real concrete example where there is a reason to
prefer  radians when computing sin/cos/tan? (Not their derivatives!)

The latter of the three examples is most disappointing:

C:\>python
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from math import sin,asin,pi
>>> sin(pi/6)           #  == 0.5
0.49999999999999994
>>> degrees(asin(0.5))  #  == 30 
30.000000000000004
>>> sin(pi)             #  == 0
1.2246063538223773e-016

I understand why this fails - I just think the world is wrong.
Represent angles using some rational fraction of a circle and all this
crap goes away. Why convert to a unit which eliminates the possibility
of an exact representation of any result at all?

> In the example above, Microsoft - something special as ever - seems to expect
> the argument in degrees (which is quite unusual)

The microsoft calculator has a checkbox for switching between degrees
and radians and gets all of the analytical results above correct. We
live in a mad world....

Jon



More information about the Python-list mailing list