From 4316dfc2fa239a6f54ce870656389a9ab80b81bc Mon Sep 17 00:00:00 2001 From: tadf Date: Sun, 5 Jul 2009 13:46:10 +0000 Subject: * complex.c (nucomp_s_polar): now arg is optional. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ complex.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26f6fe5ea..e31b80f3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Jul 5 22:43:13 2009 Tadayoshi Funaba + + * complex.c (nucomp_s_polar): now arg is optional. + Sun Jul 5 20:40:35 2009 Tadayoshi Funaba * complex.c (float_arg): returns PI for -0.0. diff --git a/complex.c b/complex.c index d64c62812..3ccc50974 100644 --- a/complex.c +++ b/complex.c @@ -548,13 +548,25 @@ f_complex_polar(VALUE klass, VALUE x, VALUE y) /* * call-seq: - * Complex.polar(abs, arg) -> complex + * Complex.polar(abs[, arg]) -> complex * * Returns a complex object which denotes the given polar form. */ static VALUE -nucomp_s_polar(VALUE klass, VALUE abs, VALUE arg) +nucomp_s_polar(int argc, VALUE *argv, VALUE klass) { + VALUE abs, arg; + + switch (rb_scan_args(argc, argv, "11", &abs, &arg)) { + case 1: + nucomp_real_check(abs); + arg = ZERO; + break; + default: + nucomp_real_check(abs); + nucomp_real_check(arg); + break; + } return f_complex_polar(klass, abs, arg); } @@ -1260,7 +1272,7 @@ rb_complex_new(VALUE x, VALUE y) VALUE rb_complex_polar(VALUE x, VALUE y) { - return nucomp_s_polar(rb_cComplex, x, y); + return f_complex_polar(rb_cComplex, x, y); } static VALUE nucomp_s_convert(int argc, VALUE *argv, VALUE klass); @@ -1840,7 +1852,7 @@ Init_Complex(void) 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, 2); + rb_define_singleton_method(rb_cComplex, "polar", nucomp_s_polar, -1); rb_define_global_function("Complex", nucomp_f_complex, -1); -- cgit