math module broken?

Dan Sommers me at privacy.net
Sat Jul 24 16:54:54 EDT 2004


On 24 Jul 2004 12:44:30 -0700,
danb_83 at yahoo.com (Dan Bishop) wrote:

> Dan Sommers <me at privacy.net> wrote in message news:<m2hdrxr1iz.fsf at unique.fully.qualified.domain.name.yeah.right>...
>> On 23 Jul 2004 23:00:18 -0700,
>> danb_83 at yahoo.com (Dan Bishop) wrote:
>> 
>> > danb_83 at yahoo.com (Dan Bishop) wrote in message news:<ad052e5c.0407231555.53f3ea11 at posting.google.com>...
>> 
>> >> def mysin(x):
>> >> return math.sin(math.radians(x))
>> 
>> > Even better:
>> 
>> > def mysin(x):
>> >    return math.sin(math.radians(x % 360))
>> 
>> Why?
>> 
>> >>> for x in range( 20 ):
>> print '%.12f %.12f' % (math.sin( math.radians( x ) ), math.sin( math.radians( x % 360 ) ))
>> [2 identical columns]

> It's not suprising that they're identical: When 0 <= x < 360, then x % 360 == x.

Yes, obviously, no surprise there.  Duh!  (smacks self on forehead)

I do, hoever, agree with Peter Otten about very large integers denoting
angles in degreen being unlikely.  Usually, the 'mod 2pi' ends up in the
calculation of the angle rather than in the call to math.<whatever>.

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
Never play leapfrog with a unicorn.



More information about the Python-list mailing list