diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-16 08:15:05 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-16 08:15:05 +0900 |
commit | ca524bcd494e2f284c3211cad8e8dde70e8aa86a (patch) | |
tree | 0b64cd0673bacdb2209c7b5e8e97244e7f3f38f9 | |
parent | 34019a22eb41206e3d5d1ac29b3874275aa7f71c (diff) |
Expanded f_numerator
-rw-r--r-- | complex.c | 13 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | rational.c | 6 |
3 files changed, 16 insertions, 4 deletions
@@ -192,6 +192,18 @@ f_arg(VALUE x) } inline static VALUE +f_numerator(VALUE x) +{ + if (RB_TYPE_P(x, T_RATIONAL)) { + return RRATIONAL(x)->num; + } + if (RB_FLOAT_TYPE_P(x)) { + return rb_float_numerator(x); + } + return x; +} + +inline static VALUE f_denominator(VALUE x) { if (RB_TYPE_P(x, T_RATIONAL)) { @@ -221,7 +233,6 @@ f_negate(VALUE x) return rb_funcall(x, id_negate, 0); } -fun1(numerator) fun1(real_p) inline static VALUE diff --git a/internal.h b/internal.h index bd82231d37..2f0a5afe80 100644 --- a/internal.h +++ b/internal.h @@ -2029,6 +2029,7 @@ VALUE rb_rational_abs(VALUE self); VALUE rb_rational_cmp(VALUE self, VALUE other); VALUE rb_rational_pow(VALUE self, VALUE other); VALUE rb_numeric_quo(VALUE x, VALUE y); +VALUE rb_float_numerator(VALUE x); VALUE rb_float_denominator(VALUE x); /* re.c */ diff --git a/rational.c b/rational.c index 7607628cb0..7113e15e8e 100644 --- a/rational.c +++ b/rational.c @@ -2057,8 +2057,8 @@ static VALUE float_to_r(VALUE self); * * See also Float#denominator. */ -static VALUE -float_numerator(VALUE self) +VALUE +rb_float_numerator(VALUE self) { double d = RFLOAT_VALUE(self); VALUE r; @@ -2777,7 +2777,7 @@ Init_Rational(void) rb_define_method(rb_cInteger, "numerator", integer_numerator, 0); rb_define_method(rb_cInteger, "denominator", integer_denominator, 0); - rb_define_method(rb_cFloat, "numerator", float_numerator, 0); + rb_define_method(rb_cFloat, "numerator", rb_float_numerator, 0); rb_define_method(rb_cFloat, "denominator", rb_float_denominator, 0); rb_define_method(rb_cNilClass, "to_r", nilclass_to_r, 0); |