why no arg, abs methods for comlex type?

Bengt Richter bokr at oz.net
Sat Aug 6 12:11:47 EDT 2005


On Sat, 06 Aug 2005 06:44:03 GMT, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:

>On Fri, 05 Aug 2005 18:24:26 +0200, Daniel Schüle
><uval at rz.uni-karlsruhe.de> declaimed the following in comp.lang.python:
>
>> >>c = 1+1j
>> >>c.arg(angle_mode = cmath.GRAD) -> 45.0
>> > 
>> > 
>> > 	Is that right? The result looks more like Degrees...
>> 
>> maybe I confuse, in german one would say "45 Grad"
>> I took a freedom to translate it directly :)
>> well, my calculator shows a "D"
>> which most likely stands for Degree, I cannot tell for sure
>
>	45 Degrees => 50 Grad
>
>	2PI => 360 Degree => 400 Grad
>
>	(and military protractors are the only place I've seen Grads
>used)
No one seems to have mentioned 2PI => 1 circle as in unit circles.
IIRC, back in the day before math chips, we implemented all the trig
functions in terms of angles where some number of bits respresented
one circle, for best resolution of angles with a given number of bits.
Also for compatibility with angular input devices. Also for the natural
modulo 2PI effect of representing an angle as an int, with unsigned interval
[0..2PI) or signed interval [-PI..PI). IIRC, FFTs involve phase in steps of
2PI/2**n also (for power-of-2 decimation effectively dividing the unit circle
in terms of powers of e**-i*(2*pi/2**n)) (where i is imaginary 0+1j). Hm, let' see,
for 45-degree deltas (2PI/2**3) ...

 >>> import cmath
 >>> (cmath.e+0j)**(-2j*cmath.pi/2**3)
 (0.70710678118654757-0.70710678118654746j)

 >>> for c in [((cmath.e+0j)**(-2j*cmath.pi/2**3))**i for i in xrange(8)]: print c
 ...
 (1+0j)
 (0.707106781187-0.707106781187j)
 (1.5701957963e-016-1j)
 (-0.707106781187-0.707106781187j)
 (-1-3.1403915926e-016j)
 (-0.707106781187+0.707106781187j)
 (-4.71058738891e-016+1j)
 (0.707106781187+0.707106781187j)

Regards,
Bengt Richter



More information about the Python-list mailing list