Project

General

Profile

Feature #3755 ยป complex-cis.patch

runpaint (Run Paint Run Run), 08/29/2010 04:31 AM

View differences:

complex.c
/*
* call-seq:
* Complex.cis(radians) -> complex
*
* Given an angle in radians, returns a Complex object whose real part is equal
* to the angle's cosine, and whose imaginary part is equal to the angle's
* sine. If the angle is itself a Complex number of the form a+bi, the result
* has a real part of <tt>Math.exp(-b) * Math.cos(a)</tt>, and an imaginary
* part of <tt>Math.exp(-b) * Math.sin(a)</tt>. A TypeError is raised unless
* the angle is a Numeric.
*/
static VALUE
nucomp_s_cis(VALUE klass, VALUE radians)
{
VALUE a, b;
if (!k_numeric_p(radians)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Numeric)",
rb_obj_classname(radians));
}
if (k_complex_p(radians)) {
get_dat1(radians);
a = f_mul(m_exp_bang(f_negate(dat->imag)), m_cos(dat->real));
b = f_mul(m_exp_bang(f_negate(dat->imag)), m_sin(dat->real));
}
else {
a = m_cos(radians);
b = m_sin(radians);
}
return f_complex_new_bang2(rb_cComplex, a, b);
}
/*
* call-seq:
* cmp.real -> real
*
* Returns the real part.
......
rb_define_singleton_method(rb_cComplex, "rectangular", nucomp_s_new, -1);
rb_define_singleton_method(rb_cComplex, "rect", nucomp_s_new, -1);
rb_define_singleton_method(rb_cComplex, "polar", nucomp_s_polar, -1);
rb_define_singleton_method(rb_cComplex, "cis", nucomp_s_cis, 1);
rb_define_global_function("Complex", nucomp_f_complex, -1);
    (1-1/1)