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))
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)
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)
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()
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)
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)
def arith_exact_inexact(self): return values.W_Complex(self.real.arith_exact_inexact(), self.imag.arith_exact_inexact())
def complex_conjugate(self): return values.W_Complex(self.real, self.imag.arith_unarysub())
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))
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))
def imaginary(val): return values.W_Complex(values.W_Fixnum.ZERO, val)