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

ruby-changes:42403

From: nobu <ko1@a...>
Date: Sun, 3 Apr 2016 08:37:58 +0900 (JST)
Subject: [ruby-changes:42403] nobu:r54477 (trunk): numeric.c: dbl2ival no longer rounds

nobu	2016-04-03 09:34:31 +0900 (Sun, 03 Apr 2016)

  New Revision: 54477

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54477

  Log:
    numeric.c: dbl2ival no longer rounds
    
    * numeric.c (flodivmod): round division if it is a finite number
      and module is required.
    * numeric.c (dbl2ival): do not round here.
    * numeric.c (flo_ceil): use dbl2ival.
    * numeric.c (flo_round): round explicitly.

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
Index: numeric.c
===================================================================
--- numeric.c	(revision 54476)
+++ numeric.c	(revision 54477)
@@ -1008,8 +1008,10 @@ flodivmod(double x, double y, double *di https://github.com/ruby/ruby/blob/trunk/numeric.c#L1008
     }
     if (isinf(x) && !isinf(y))
 	div = x;
-    else
+    else {
 	div = (x - mod) / y;
+	if (modp && divp) div = round(div);
+    }
     if (y*mod < 0) {
 	mod += y;
 	div -= 1.0;
@@ -1066,7 +1068,6 @@ flo_mod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1068
 static VALUE
 dbl2ival(double d)
 {
-    d = round(d);
     if (FIXABLE(d)) {
 	return LONG2FIX((long)d);
     }
@@ -1761,13 +1762,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L1762
 flo_ceil(VALUE num)
 {
     double f = ceil(RFLOAT_VALUE(num));
-    long val;
-
-    if (!FIXABLE(f)) {
-	return rb_dbl2big(f);
-    }
-    val = (long)f;
-    return LONG2FIX(val);
+    return dbl2ival(f);
 }
 
 /*
@@ -1856,7 +1851,7 @@ flo_round(int argc, VALUE *argv, VALUE n https://github.com/ruby/ruby/blob/trunk/numeric.c#L1851
     }
     number  = RFLOAT_VALUE(num);
     if (ndigits == 0) {
-	return dbl2ival(number);
+	return dbl2ival(round(number));
     }
     frexp(number, &binexp);
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54476)
+++ ChangeLog	(revision 54477)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Apr  3 09:34:29 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (flodivmod): round division if it is a finite number
+	  and module is required.
+
+	* numeric.c (dbl2ival): do not round here.
+
+	* numeric.c (flo_ceil): use dbl2ival.
+
+	* numeric.c (flo_round): round explicitly.
+
 Sat Apr  2 15:24:18 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/intern.h (rb_check_arity): returns argc.

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

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