diff options
author | S-H-GAMELINKS <gamelinks007@gmail.com> | 2021-10-03 17:16:58 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-10-10 09:29:53 +0900 |
commit | d25af1f44e8920e15c5cab7808757e28fa9f6492 (patch) | |
tree | 0e485a8b4cd81db875ec4cc5d58581439d3310b9 /numeric.c | |
parent | 6678bb66795a7d851698b4e78035d113b985d415 (diff) |
Add flo_ndigits function
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4926
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -1876,13 +1876,19 @@ rb_float_floor(VALUE num, int ndigits) * (0.3 / 0.1).floor #=> 2 (!) */ -static VALUE -flo_floor(int argc, VALUE *argv, VALUE num) +static int +flo_ndigits(int argc, VALUE *argv) { - int ndigits = 0; if (rb_check_arity(argc, 0, 1)) { - ndigits = NUM2INT(argv[0]); + return NUM2INT(argv[0]); } + return 0; +} + +static VALUE +flo_floor(int argc, VALUE *argv, VALUE num) +{ + int ndigits = flo_ndigits(argc, argv); return rb_float_floor(num, ndigits); } @@ -1928,11 +1934,7 @@ flo_floor(int argc, VALUE *argv, VALUE num) static VALUE flo_ceil(int argc, VALUE *argv, VALUE num) { - int ndigits = 0; - - if (rb_check_arity(argc, 0, 1)) { - ndigits = NUM2INT(argv[0]); - } + int ndigits = flo_ndigits(argc, argv); return rb_float_ceil(num, ndigits); } |