[前][次][番号順一覧][スレッド一覧]

ruby-changes:56567

From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Jul 2019 08:26:26 +0900 (JST)
Subject: [ruby-changes:56567] Nobuyoshi Nakada: ca524bcd49 (master): Expanded f_numerator

https://git.ruby-lang.org/ruby.git/commit/?id=ca524bcd49

From ca524bcd494e2f284c3211cad8e8dde70e8aa86a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 16 Jul 2019 08:15:05 +0900
Subject: Expanded f_numerator


diff --git a/complex.c b/complex.c
index 74d91b0..fa00036 100644
--- a/complex.c
+++ b/complex.c
@@ -192,6 +192,18 @@ f_arg(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L192
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/complex.c#L233
     return rb_funcall(x, id_negate, 0);
 }
 
-fun1(numerator)
 fun1(real_p)
 
 inline static VALUE
diff --git a/internal.h b/internal.h
index bd82231..2f0a5af 100644
--- a/internal.h
+++ b/internal.h
@@ -2029,6 +2029,7 @@ VALUE rb_rational_abs(VALUE self); https://github.com/ruby/ruby/blob/trunk/internal.h#L2029
 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 7607628..7113e15 100644
--- a/rational.c
+++ b/rational.c
@@ -2057,8 +2057,8 @@ static VALUE float_to_r(VALUE self); https://github.com/ruby/ruby/blob/trunk/rational.c#L2057
  *
  * 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) https://github.com/ruby/ruby/blob/trunk/rational.c#L2777
     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);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]