ruby-changes:12832
From: matz <ko1@a...>
Date: Mon, 17 Aug 2009 07:29:08 +0900 (JST)
Subject: [ruby-changes:12832] Ruby:r24561 (trunk): * numeric.c (num_imaginary): num#i to return imaginary counterpart
matz 2009-08-17 07:28:48 +0900 (Mon, 17 Aug 2009) New Revision: 24561 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24561 Log: * numeric.c (num_imaginary): num#i to return imaginary counterpart of the given numeric. * complex.c (Init_Complex): undef #i for complex numbers. Modified files: trunk/ChangeLog trunk/complex.c trunk/numeric.c Index: complex.c =================================================================== --- complex.c (revision 24560) +++ complex.c (revision 24561) @@ -1906,6 +1906,7 @@ rb_undef_method(rb_cComplex, "round"); rb_undef_method(rb_cComplex, "step"); rb_undef_method(rb_cComplex, "truncate"); + rb_undef_method(rb_cComplex, "i"); #if 0 /* NUBY */ rb_undef_method(rb_cComplex, "//"); Index: ChangeLog =================================================================== --- ChangeLog (revision 24560) +++ ChangeLog (revision 24561) @@ -1,3 +1,10 @@ +Mon Aug 17 07:16:10 2009 Yukihiro Matsumoto <matz@r...> + + * numeric.c (num_imaginary): num#i to return imaginary counterpart + of the given numeric. + + * complex.c (Init_Complex): undef #i for complex numbers. + Mon Aug 17 00:17:33 2009 Tadayoshi Funaba <tadf@d...> * lib/complex.rb, lib/rational.rb: added warning messages. Index: numeric.c =================================================================== --- numeric.c (revision 24560) +++ numeric.c (revision 24561) @@ -238,6 +238,21 @@ /* * call-seq: + * num.i -> Complex(0,num) + * + * Returns the corresponding imaginary number. + * Not available for complex numbers. + */ + +static VALUE +num_imaginary(VALUE num) +{ + return rb_complex_new(INT2FIX(0), num); +} + + +/* + * call-seq: * -num -> numeric * * Unary Minus---Returns the receiver's value, negated. @@ -3154,6 +3169,7 @@ rb_define_method(rb_cNumeric, "initialize_copy", num_init_copy, 1); rb_define_method(rb_cNumeric, "coerce", num_coerce, 1); + rb_define_method(rb_cNumeric, "i", num_imaginary, 0); rb_define_method(rb_cNumeric, "+@", num_uplus, 0); rb_define_method(rb_cNumeric, "-@", num_uminus, 0); rb_define_method(rb_cNumeric, "<=>", num_cmp, 1); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/