summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-07 02:26:19 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-07 02:26:19 +0000
commitc4216a26e2c9b3754abc3225de1732c50803433b (patch)
tree44f48a2471229fb3bd81bebe4ba79bda9ddf27b6
parent175f3b2d7aa6426bb36943cbf13fb1bf40d017bb (diff)
* util.c (ruby_strtod): 0.0000000000000000001 == 0.0 should be false.
[ruby-talk:99318] [ruby-dev:23465] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--util.c48
2 files changed, 26 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 010082fbf4..4b7b50b101 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri May 7 11:17:27 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * util.c (ruby_strtod): 0.0000000000000000001 == 0.0 should be false.
+ [ruby-talk:99318] [ruby-dev:23465]
+
Thu May 6 22:27:32 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* ext/socket/socket.c (ippaddr): use NUMERICHOST if can not resolve
diff --git a/util.c b/util.c
index 13c4f87d09..56da0f54b4 100644
--- a/util.c
+++ b/util.c
@@ -744,9 +744,10 @@ ruby_strtod(string, endPtr)
* unnecessary overflow on I alone). In this
* case, fracExp is incremented one for each
* dropped digit. */
- int mantSize; /* Number of digits in mantissa. */
- int decPt; /* Number of mantissa digits BEFORE decimal
- * point. */
+ int mantSize = 0; /* Number of digits in mantissa. */
+ int decPt = FALSE; /* mantissa has decimal point. */
+ const char *pMant; /* Temporarily holds location of mantissa
+ * in string. */
const char *pExp; /* Temporarily holds location of exponent
* in string. */
@@ -770,28 +771,30 @@ ruby_strtod(string, endPtr)
sign = FALSE;
}
- /* skip preceding zeros */
- if (*p == '0') {
- while (*p == '0')
- p++;
- p--;
- }
-
/*
* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point.
*/
- decPt = -1;
- for (mantSize = 0; ; mantSize += 1) {
- c = *p;
+ for ( ; c = *p; p += 1) {
if (!ISDIGIT(c)) {
- if ((c != '.') || (decPt >= 0)) {
+ if (c != '.' || decPt) {
break;
}
- decPt = mantSize;
+ decPt = TRUE;
+ }
+ else {
+ if (decPt) { /* already in fractional part */
+ fracExp -= 1;
+ }
+ if (mantSize) { /* already in mantissa */
+ mantSize += 1;
+ }
+ else if (c != '0') { /* have entered mantissa */
+ mantSize += 1;
+ pMant = p;
+ }
}
- p += 1;
}
/*
@@ -802,20 +805,11 @@ ruby_strtod(string, endPtr)
*/
pExp = p;
- p -= mantSize;
- if (decPt < 0) {
- decPt = mantSize;
- }
- else {
- mantSize -= 1; /* One of the digits was the point. */
- }
+ p = pMant; /* valid if mantSize > 0 */
if (mantSize > 18) {
- fracExp = decPt - 18;
+ fracExp += (mantSize - 18);
mantSize = 18;
}
- else {
- fracExp = decPt - mantSize;
- }
if (mantSize == 0) {
fraction = 0.0;
p = string;