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

ruby-changes:68341

From: S-H-GAMELINKS <ko1@a...>
Date: Sun, 10 Oct 2021 09:30:22 +0900 (JST)
Subject: [ruby-changes:68341] d25af1f44e (master): Add flo_ndigits function

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

From d25af1f44e8920e15c5cab7808757e28fa9f6492 Mon Sep 17 00:00:00 2001
From: S-H-GAMELINKS <gamelinks007@g...>
Date: Sun, 3 Oct 2021 17:16:58 +0900
Subject: Add flo_ndigits function

---
 numeric.c | 20 +++++++++++---------
 1 file 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) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1876
  *     (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) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1934
 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);
 }
 
-- 
cgit v1.2.1


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

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