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

ruby-changes:17014

From: nobu <ko1@a...>
Date: Mon, 16 Aug 2010 19:23:33 +0900 (JST)
Subject: [ruby-changes:17014] Ruby:r29011 (trunk): From b80689141673b93e8d12968c3196ec6a2331da45 Mon Sep 17 00:00:00 2001

nobu	2010-08-16 19:23:22 +0900 (Mon, 16 Aug 2010)

  New Revision: 29011

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

  Log:
    From b80689141673b93e8d12968c3196ec6a2331da45 Mon Sep 17 00:00:00 2001
    From: Nobuyoshi Nakada <nobu@r...>
    Date: Mon, 16 Aug 2010 18:55:11 +0900
    Subject: [PATCH 2/2] 	* util.c (ruby_dtoa, ruby_hdtoa): use same representations for
     	  Infinity and NaN.  a part of a patch from Peter Weldon at
     	  [ruby-core:31725].
    
    ---
     util.c |   14 ++++++++------
     1 files changed, 8 insertions(+), 6 deletions(-)
    
    diff --git a/util.c b/util.c
    index 065b2f1..76ba457 100644
    --- a/util.c
    +++ b/util.c
    @@ -3145,6 +3145,10 @@ freedtoa(char *s)
     }
     #endif
    
    +static const char INFSTR[] = "Infinity";
    +static const char NANSTR[] = "NaN";
    +static const char ZEROSTR[] = "0";
    +
     /* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
      *
      * Inspired by "How to Print Floating-Point Numbers Accurately" by
    @@ -3263,9 +3267,9 @@ ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
             *decpt = 9999;
     #ifdef IEEE_Arith
             if (!word1(d) && !(word0(d) & 0xfffff))
    -            return rv_strdup("Infinity", rve);
    +            return rv_strdup(INFSTR, rve);
     #endif
    -        return rv_strdup("NaN", rve);
    +        return rv_strdup(NANSTR, rve);
         }
     #endif
     #ifdef IBM
    @@ -3273,7 +3277,7 @@ ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
     #endif
         if (!dval(d)) {
             *decpt = 1;
    -        return rv_strdup("0", rve);
    +        return rv_strdup(ZEROSTR, rve);
         }
    
     #ifdef SET_INEXACT
    @@ -3897,8 +3901,6 @@ ruby_each_words(const char *str, void (*func)(const char*, int, void*), void *ar
    
     #define	DBL_MANH_SIZE	20
     #define	DBL_MANL_SIZE	32
    -#define	INFSTR	"Infinity"
    -#define	NANSTR	"NaN"
     #define	DBL_ADJ	(DBL_MAX_EXP - 2)
     #define	SIGFIGS	((DBL_MANT_DIG + 3) / 4 + 1)
     #define dexp_get(u) ((int)(word0(u) >> Exp_shift) & ~Exp_msk1)
    @@ -3959,7 +3961,7 @@ ruby_hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,
     	}
     	else if (d == 0.0) { /* FP_ZERO */
     	    *decpt = 1;
    -	    return rv_strdup("0", rve);
    +	    return rv_strdup(ZEROSTR, rve);
     	}
     	else if (dexp_get(u)) { /* FP_NORMAL */
     	    *decpt = dexp_get(u) - DBL_ADJ;
    --
    1.7.0.4

  Modified files:
    trunk/ChangeLog
    trunk/util.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29010)
+++ ChangeLog	(revision 29011)
@@ -1,5 +1,9 @@
-Mon Aug 16 19:22:31 2010  Nobuyoshi Nakada  <nobu@r...>
+Mon Aug 16 19:23:19 2010  Nobuyoshi Nakada  <nobu@r...>
 
+	* util.c (ruby_dtoa, ruby_hdtoa): use same representations for
+	  Infinity and NaN.  a part of a patch from Peter Weldon at
+	  [ruby-core:31725].
+
 	* util.c (ruby_hdtoa): fixed buffer overrun.  based on a patch
 	  from Peter Weldon at [ruby-core:31725].
 
Index: util.c
===================================================================
--- util.c	(revision 29010)
+++ util.c	(revision 29011)
@@ -3145,6 +3145,10 @@
 }
 #endif
 
+static const char INFSTR[] = "Infinity";
+static const char NANSTR[] = "NaN";
+static const char ZEROSTR[] = "0";
+
 /* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
  *
  * Inspired by "How to Print Floating-Point Numbers Accurately" by
@@ -3263,9 +3267,9 @@
         *decpt = 9999;
 #ifdef IEEE_Arith
         if (!word1(d) && !(word0(d) & 0xfffff))
-            return rv_strdup("Infinity", rve);
+            return rv_strdup(INFSTR, rve);
 #endif
-        return rv_strdup("NaN", rve);
+        return rv_strdup(NANSTR, rve);
     }
 #endif
 #ifdef IBM
@@ -3273,7 +3277,7 @@
 #endif
     if (!dval(d)) {
         *decpt = 1;
-        return rv_strdup("0", rve);
+        return rv_strdup(ZEROSTR, rve);
     }
 
 #ifdef SET_INEXACT
@@ -3897,8 +3901,6 @@
 
 #define	DBL_MANH_SIZE	20
 #define	DBL_MANL_SIZE	32
-#define	INFSTR	"Infinity"
-#define	NANSTR	"NaN"
 #define	DBL_ADJ	(DBL_MAX_EXP - 2)
 #define	SIGFIGS	((DBL_MANT_DIG + 3) / 4 + 1)
 #define dexp_get(u) ((int)(word0(u) >> Exp_shift) & ~Exp_msk1)
@@ -3959,7 +3961,7 @@
 	}
 	else if (d == 0.0) { /* FP_ZERO */
 	    *decpt = 1;
-	    return rv_strdup("0", rve);
+	    return rv_strdup(ZEROSTR, rve);
 	}
 	else if (dexp_get(u)) { /* FP_NORMAL */
 	    *decpt = dexp_get(u) - DBL_ADJ;

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

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