inline static VALUE f_rational_new_bang2(VALUE klass, VALUE x, VALUE y) { assert(f_positive_p(y)); assert(f_nonzero_p(y)); return nurat_s_new_internal(klass, x, y); }
/* * call-seq: * num.arg -> 0 or float * num.angle -> 0 or float * num.phase -> 0 or float * * Returns 0 if the value is positive, pi otherwise. */ static VALUE numeric_arg(VALUE self) { if (f_positive_p(self)) return INT2FIX(0); return rb_const_get(rb_mMath, id_PI); }
static VALUE nurat_abs(VALUE self) { if (f_positive_p(self)) return self; return f_negate(self); }
static VALUE m_sqrt(VALUE x) { if (f_real_p(x)) { if (f_positive_p(x)) return m_sqrt_bang(x); return f_complex_new2(rb_cComplex, ZERO, m_sqrt_bang(f_negate(x))); } else { get_dat1(x); if (f_negative_p(dat->imag)) return f_conj(m_sqrt(f_conj(x))); else { VALUE a = f_abs(x); return f_complex_new2(rb_cComplex, m_sqrt_bang(f_div(f_add(a, dat->real), TWO)), m_sqrt_bang(f_div(f_sub(a, dat->real), TWO))); } } }