ruby-changes:56568
From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Jul 2019 08:26:26 +0900 (JST)
Subject: [ruby-changes:56568] Nobuyoshi Nakada: 34019a22eb (master): Expanded f_denominator
https://git.ruby-lang.org/ruby.git/commit/?id=34019a22eb From 34019a22eb41206e3d5d1ac29b3874275aa7f71c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 16 Jul 2019 07:58:47 +0900 Subject: Expanded f_denominator diff --git a/complex.c b/complex.c index bcdc486..74d91b0 100644 --- a/complex.c +++ b/complex.c @@ -191,7 +191,17 @@ f_arg(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L191 return rb_funcall(x, id_arg, 0); } -fun1(denominator) +inline static VALUE +f_denominator(VALUE x) +{ + if (RB_TYPE_P(x, T_RATIONAL)) { + return RRATIONAL(x)->den; + } + if (RB_FLOAT_TYPE_P(x)) { + return rb_float_denominator(x); + } + return INT2FIX(1); +} inline static VALUE f_negate(VALUE x) @@ -1252,7 +1262,7 @@ nucomp_numerator(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1262 get_dat1(self); - cd = f_denominator(self); + cd = nucomp_denominator(self); return f_complex_new2(CLASS_OF(self), f_mul(f_numerator(dat->real), f_div(cd, f_denominator(dat->real))), diff --git a/internal.h b/internal.h index fb184e2..bd82231 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_denominator(VALUE x); /* re.c */ VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline); diff --git a/rational.c b/rational.c index e137ac2..7607628 100644 --- a/rational.c +++ b/rational.c @@ -2080,8 +2080,8 @@ float_numerator(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L2080 * * See also Float#numerator. */ -static VALUE -float_denominator(VALUE self) +VALUE +rb_float_denominator(VALUE self) { double d = RFLOAT_VALUE(self); VALUE r; @@ -2778,7 +2778,7 @@ Init_Rational(void) https://github.com/ruby/ruby/blob/trunk/rational.c#L2778 rb_define_method(rb_cInteger, "denominator", integer_denominator, 0); rb_define_method(rb_cFloat, "numerator", float_numerator, 0); - rb_define_method(rb_cFloat, "denominator", float_denominator, 0); + rb_define_method(rb_cFloat, "denominator", rb_float_denominator, 0); rb_define_method(rb_cNilClass, "to_r", nilclass_to_r, 0); rb_define_method(rb_cNilClass, "rationalize", nilclass_rationalize, -1); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/