summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorS-H-GAMELINKS <gamelinks007@gmail.com>2021-10-03 17:16:58 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-10 09:29:53 +0900
commitd25af1f44e8920e15c5cab7808757e28fa9f6492 (patch)
tree0e485a8b4cd81db875ec4cc5d58581439d3310b9 /numeric.c
parent6678bb66795a7d851698b4e78035d113b985d415 (diff)
Add flo_ndigits function
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4926
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/numeric.c b/numeric.c
index 3b481b3869..4a4a128bb5 100644
--- a/numeric.c
+++ b/numeric.c
@@ -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);
}