Re: deriving from complex

2006-03-08 Thread ajsiegel
Meant: http://codespeak.net/svn/pypy/dist/pypy/module/__builtin__/app_complex.py -- http://mail.python.org/mailman/listinfo/python-list

Re: deriving from complex

2006-03-08 Thread ajsiegel
Schüle Daniel wrote: > thank you > I will have to take a closer look on __new__ > > Regards, Daniel The pypy implementation of the complex builtin may give you some clues. I found it helpful. http://codespeak.net/svn/pypy/dist/pypy/lib/cmath.py Art -- http://mail.python.org/mailman/listinfo/

Re: deriving from complex

2006-03-07 Thread Schüle Daniel
thank you I will have to take a closer look on __new__ Regards, Daniel -- http://mail.python.org/mailman/listinfo/python-list

Re: deriving from complex

2006-03-07 Thread Scott David Daniels
Schüle Daniel wrote: ... > btw I like how Ruby handles the creation of complex numbers > > c = Complex(1,1) > p = Complex.polar(1,45.0/360*2*PI) class Complex(complex): @classmethod def polar(class_, radius, angle): return class_(radius * cos(angle), radius * sin(angle)) --Sco

Re: deriving from complex

2006-03-07 Thread Scott David Daniels
Scott David Daniels wrote: > Schüle Daniel wrote: >> ... And, of course, I reply with a cutto-pasto (pre-success code). > ... > Which will produce instances of Complex, or: > class Complex(complex): > def __new__(class_, x, y=0.0, polar=False): > if polar: >

Re: deriving from complex

2006-03-07 Thread Scott David Daniels
Schüle Daniel wrote: > I am trying to customize the handling of complex numbers > what I am missing is a builtin possibility to create > complex numbers in polar coordinates I wrote...: > >>> def polar(r,arg): > ... re, im = r*cos(arg), r*sin(arg) > ... return re + im*1j > then I tried

Re: deriving from complex

2006-03-07 Thread Schüle Daniel
what do you think of this design? >>> def polar(x,y=None): ... if type(x) in (list,tuple) and len(x) == 2 and y is None: ... return complex(x[0]*cos(x[1]), x[0]*sin(x[1])) ... if type(x) is complex and y is None: ... return (abs(x), atan2(x.imag,x.real)) ... if

deriving from complex

2006-03-07 Thread Schüle Daniel
Hello I am trying to customize the handling of complex numbers what I am missing is a builtin possibility to create complex numbers in polar coordinates so first I wrote a standalone function >>> def polar(r,arg): ... re, im = r*cos(arg), r*sin(arg) ... return re + im*1j then I tried t