static VALUE nucomp_div(VALUE self, VALUE other) { if (k_complex_p(other)) { get_dat2(self, other); if (TYPE(adat->real) == T_FLOAT || TYPE(adat->imag) == T_FLOAT || TYPE(bdat->real) == T_FLOAT || TYPE(bdat->imag) == T_FLOAT) { VALUE magn = m_hypot(bdat->real, bdat->imag); VALUE tmp = f_complex_new_bang2(CLASS_OF(self), f_div(bdat->real, magn), f_div(bdat->imag, magn)); return f_div(f_mul(self, f_conj(tmp)), magn); } return f_div(f_mul(self, f_conj(other)), f_abs2(other)); } if (k_numeric_p(other) && f_real_p(other)) { get_dat1(self); return f_complex_new2(CLASS_OF(self), f_div(dat->real, other), f_div(dat->imag, other)); } return rb_num_coerce_bin(self, other, '/'); }
/* * call-seq: * cmp.abs -> real * cmp.magnitude -> real * * Returns the absolute part of its polar form. * * Complex(-1).abs #=> 1 * Complex(3.0, -4.0).abs #=> 5.0 */ static VALUE nucomp_abs(VALUE self) { get_dat1(self); if (f_zero_p(dat->real)) { VALUE a = f_abs(dat->imag); if (k_float_p(dat->real) && !k_float_p(dat->imag)) a = f_to_f(a); return a; } if (f_zero_p(dat->imag)) { VALUE a = f_abs(dat->real); if (!k_float_p(dat->real) && k_float_p(dat->imag)) a = f_to_f(a); return a; } return m_hypot(dat->real, dat->imag); }
static VALUE nucomp_abs(VALUE self) { get_dat1(self); return m_hypot(dat->real, dat->imag); }