Beispiel #1
0
 def arith_mul_same(self, other):
     assert isinstance(other, values.W_Complex)
     re1 = self.real.arith_mul(other.real)
     re2 = self.imag.arith_mul(other.imag)
     im1 = self.real.arith_mul(other.imag)
     im2 = self.imag.arith_mul(other.real)
     return values.W_Complex(re1.arith_sub(re2), im1.arith_add(im2))
Beispiel #2
0
 def arith_div_same(self, other):
     assert isinstance(other, values.W_Complex)
     if other.imag.arith_eq(values.W_Fixnum.make(0)):
         divisor = other.real
         r = self.real.arith_div(divisor)
         i = self.imag.arith_div(divisor)
         return values.W_Complex(r, i)
     factor = other.reciprocal()
     return self.arith_mul(factor)
Beispiel #3
0
 def arith_cosh(self):
     "cosh(a+bi)=cosh a cos b + i sinh a sin b"
     r = self.real.arith_cosh().arith_mul(self.imag.arith_cos())
     i = self.real.arith_sinh().arith_mul(self.imag.arith_sin())
     return values.W_Complex(r, i)
Beispiel #4
0
 def arith_cos(self):
     "cos(a+bi)=cos a cosh b - i sin a sinh b"
     r = self.real.arith_cos().arith_mul(self.imag.arith_cosh())
     i = self.real.arith_sin().arith_mul(self.imag.arith_sinh())
     return values.W_Complex(r, i).complex_conjugate()
Beispiel #5
0
 def arith_sin(self):
     "sin(a+bi)=sin a cosh b + i cos a sinh b"
     r = self.real.arith_sin().arith_mul(self.imag.arith_cosh())
     i = self.real.arith_cos().arith_mul(self.imag.arith_sinh())
     return values.W_Complex(r, i)
Beispiel #6
0
 def arith_exp(self):
     r = self.real.arith_exp()
     cos = self.imag.arith_cos()
     sin = self.imag.arith_sin()
     return values.W_Complex(cos, sin).arith_mul(r)
Beispiel #7
0
 def arith_exact_inexact(self):
     return values.W_Complex(self.real.arith_exact_inexact(),
                             self.imag.arith_exact_inexact())
Beispiel #8
0
 def complex_conjugate(self):
     return values.W_Complex(self.real, self.imag.arith_unarysub())
Beispiel #9
0
 def arith_sub_same(self, other):
     assert isinstance(other, values.W_Complex)
     return values.W_Complex(self.real.arith_sub(other.real),
                             self.imag.arith_sub(other.imag))
Beispiel #10
0
 def same_numeric_class(self, other):
     if isinstance(other, values.W_Complex):
         return self, other
     return self, values.W_Complex(other, values.W_Fixnum(0))
Beispiel #11
0
def imaginary(val):
    return values.W_Complex(values.W_Fixnum.ZERO, val)