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

ruby-changes:11517

From: nobu <ko1@a...>
Date: Tue, 7 Apr 2009 01:08:34 +0900 (JST)
Subject: [ruby-changes:11517] Ruby:r23144 (trunk): * numeric.c (flo_to_s): reduce fragments if no precision lost.

nobu	2009-04-07 01:08:23 +0900 (Tue, 07 Apr 2009)

  New Revision: 23144

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

  Log:
    * numeric.c (flo_to_s): reduce fragments if no precision lost.
      c.f. [ruby-core:23075]

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
    trunk/version.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23143)
+++ ChangeLog	(revision 23144)
@@ -1,3 +1,8 @@
+Tue Apr  7 01:08:21 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (flo_to_s): reduce fragments if no precision lost.
+	  c.f. [ruby-core:23075]
+
 Mon Apr  6 23:16:08 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (CFLAGS, CXXFLAGS): override with $cflags and
Index: numeric.c
===================================================================
--- numeric.c	(revision 23143)
+++ numeric.c	(revision 23144)
@@ -522,7 +522,7 @@
 flo_to_s(VALUE flt)
 {
     enum {decimal_mant = DBL_MANT_DIG-DBL_DIG};
-    enum {float_dig = DBL_DIG+2};
+    enum {float_dig = DBL_DIG+1};
     char buf[float_dig + (decimal_mant + CHAR_BIT - 1) / CHAR_BIT + 10];
     double value = RFLOAT_VALUE(flt);
     char *p, *e;
@@ -532,12 +532,15 @@
     else if(isnan(value))
 	return rb_usascii_str_new2("NaN");
 
-    snprintf(buf, sizeof(buf), "%#.*g", float_dig, value); /* ensure to print decimal point */
+# define FLOFMT(buf, size, fmt, prec, val) snprintf(buf, size, fmt, prec, val), \
+    (void)((atof(buf) == val) || snprintf(buf, size, fmt, (prec)+1, val))
+
+    FLOFMT(buf, sizeof(buf), "%#.*g", float_dig, value); /* ensure to print decimal point */
     if (!(e = strchr(buf, 'e'))) {
 	e = buf + strlen(buf);
     }
     if (!ISDIGIT(e[-1])) { /* reformat if ended with decimal point (ex 111111111111111.) */
-	snprintf(buf, sizeof(buf), "%#.*e", float_dig - 1, value);
+	FLOFMT(buf, sizeof(buf), "%#.*e", float_dig - 1, value);
 	if (!(e = strchr(buf, 'e'))) {
 	    e = buf + strlen(buf);
 	}
Index: version.h
===================================================================
--- version.h	(revision 23143)
+++ version.h	(revision 23144)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_RELEASE_DATE "2009-04-06"
+#define RUBY_RELEASE_DATE "2009-04-07"
 #define RUBY_PATCHLEVEL -1
 #define RUBY_BRANCH_NAME "trunk"
 
@@ -8,7 +8,7 @@
 #define RUBY_VERSION_TEENY 1
 #define RUBY_RELEASE_YEAR 2009
 #define RUBY_RELEASE_MONTH 4
-#define RUBY_RELEASE_DAY 6
+#define RUBY_RELEASE_DAY 7
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];

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

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