ruby-changes:56760
From: Nobuyoshi <ko1@a...>
Date: Fri, 2 Aug 2019 11:50:21 +0900 (JST)
Subject: [ruby-changes:56760] Nobuyoshi Nakada: f9a0492b76 (master): Expanded f_ceil
https://git.ruby-lang.org/ruby.git/commit/?id=f9a0492b76 From f9a0492b76956b545c746ab0d3ec0e555e77dfcd Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 2 Aug 2019 11:25:41 +0900 Subject: Expanded f_ceil diff --git a/internal.h b/internal.h index fac8ece..5ecb229 100644 --- a/internal.h +++ b/internal.h @@ -1772,6 +1772,7 @@ VALUE rb_int_odd_p(VALUE num); https://github.com/ruby/ruby/blob/trunk/internal.h#L1772 int rb_int_positive_p(VALUE num); int rb_int_negative_p(VALUE num); VALUE rb_num_pow(VALUE x, VALUE y); +VALUE rb_float_ceil(VALUE num, int ndigits); static inline VALUE rb_num_compare_with_zero(VALUE num, ID mid) diff --git a/numeric.c b/numeric.c index 5b0ab8c..7ce6590 100644 --- a/numeric.c +++ b/numeric.c @@ -2002,12 +2002,19 @@ flo_floor(int argc, VALUE *argv, VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2002 static VALUE flo_ceil(int argc, VALUE *argv, VALUE num) { - double number, f; int ndigits = 0; if (rb_check_arity(argc, 0, 1)) { ndigits = NUM2INT(argv[0]); } + return rb_float_ceil(num, ndigits); +} + +VALUE +rb_float_ceil(VALUE num, int ndigits) +{ + double number, f; + number = RFLOAT_VALUE(num); if (number == 0.0) { return ndigits > 0 ? DBL2NUM(number) : INT2FIX(0); diff --git a/rational.c b/rational.c index 3737db4..1dc08a0 100644 --- a/rational.c +++ b/rational.c @@ -43,13 +43,6 @@ static ID id_abs, id_idiv, id_integer_p, https://github.com/ruby/ruby/blob/trunk/rational.c#L43 static VALUE nurat_to_f(VALUE self); -#define fun1(n) \ -inline static VALUE \ -f_##n(VALUE x)\ -{\ - return rb_funcall(x, id_##n, 0);\ -} - inline static VALUE f_add(VALUE x, VALUE y) { @@ -1597,7 +1590,16 @@ nurat_to_r(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L1590 } #define id_ceil rb_intern("ceil") -#define f_ceil(x) rb_funcall((x), id_ceil, 0) +static VALUE +f_ceil(VALUE x) +{ + if (RB_INTEGER_TYPE_P(x)) + return x; + if (RB_FLOAT_TYPE_P(x)) + return rb_float_ceil(x, 0); + + return rb_funcall(x, id_ceil, 0); +} #define id_quo rb_intern("quo") #define f_quo(x,y) rb_funcall((x), id_quo, 1, (y)) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/