summaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-16 22:28:48 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-16 22:28:48 +0000
commit9cd70970823e1ed98cf63060408e1c94b9b076c0 (patch)
tree9cb22719d7220c00834c6c20c6001f9ac8b6a42b /numeric.c
parent08b7b7509cc012583a561abd078855280582435c (diff)
downloadruby-9cd70970823e1ed98cf63060408e1c94b9b076c0.tar.gz
ruby-9cd70970823e1ed98cf63060408e1c94b9b076c0.tar.xz
ruby-9cd70970823e1ed98cf63060408e1c94b9b076c0.zip
* numeric.c (num_imaginary): num#i to return imaginary counterpart
of the given numeric. * complex.c (Init_Complex): undef #i for complex numbers. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index ecaf9c503..4ba69fd5d 100644
--- a/numeric.c
+++ b/numeric.c
@@ -238,6 +238,21 @@ num_uplus(VALUE num)
/*
* 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 @@ Init_Numeric(void)
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);