End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Complex.polar
Complex.polar(abs[, arg]) → complex
complex.c
View on GitHub ↗
static VALUE
nucomp_s_polar(int argc, VALUE *argv, VALUE klass)
{
VALUE abs, arg;
argc = rb_scan_args(argc, argv, "11", &abs, &arg);
nucomp_real_check(abs);
if (argc == 2) {
nucomp_real_check(arg);
}
else {
arg = ZERO;
}
if (RB_TYPE_P(abs, T_COMPLEX)) {
get_dat1(abs);
abs = dat->real;
}
if (RB_TYPE_P(arg, T_COMPLEX)) {
get_dat1(arg);
arg = dat->real;
}
return f_complex_polar(klass, abs, arg);
}
Returns a complex object which denotes the given polar form.
Example
Complex.polar(3, 0) #=> (3.0+0.0i) Complex.polar(3, Math::PI/2) #=> (1.836909530733566e-16+3.0i) Complex.polar(3, Math::PI) #=> (-3.0+3.673819061467132e-16i) Complex.polar(3, -Math::PI/2) #=> (1.836909530733566e-16-3.0i)