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

ruby-changes:12362

From: nobu <ko1@a...>
Date: Mon, 13 Jul 2009 01:18:48 +0900 (JST)
Subject: [ruby-changes:12362] Ruby:r24058 (trunk): * time.c (time_timespec): rounds subsecond toward zero.

nobu	2009-07-13 01:18:18 +0900 (Mon, 13 Jul 2009)

  New Revision: 24058

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24058

  Log:
    * time.c (time_timespec): rounds subsecond toward zero.

  Modified files:
    trunk/ChangeLog
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 24057)
+++ time.c	(revision 24058)
@@ -1499,22 +1499,17 @@
 	    double f, d;
 
 	    d = modf(RFLOAT_VALUE(num), &f);
-            if (d < 0) {
-                d += 1;
-                f -= 1;
-            }
+	    if (d >= 0) {
+		t.tv_nsec = (int)(d*1e9+0.5);
+	    }
+	    else if ((t.tv_nsec = (int)(-d*1e9+0.5)) > 0) {
+		t.tv_nsec = 1000000000 - t.tv_nsec;
+		f -= 1;
+	    }
 	    t.tv_sec = (time_t)f;
 	    if (f != t.tv_sec) {
 		rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(num));
 	    }
-	    t.tv_nsec = (int)(d*1e9+0.5);
-	    if (t.tv_nsec >= 1000000000) {
-		t.tv_nsec -= 1000000000;
-		if (++t.tv_sec <= 0) {
-		    --t.tv_nsec;
-		    t.tv_nsec = 999999999;
-		}
-	    }
 	}
 	break;
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24057)
+++ ChangeLog	(revision 24058)
@@ -1,3 +1,7 @@
+Mon Jul 13 01:18:13 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* time.c (time_timespec): rounds subsecond toward zero.
+
 Sun Jul 12 23:51:39 2009  NARUSE, Yui  <naruse@r...>
 
 	* hash.c (env_str_new): use rb_locale_str_new instead of

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

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