mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* util.c (ruby_strtod): should not convert string in the form of
"-I.FE-X" which both "I" and "F" are ommitted. [ruby-dev:23883] * test/ruby/test_float.rb (test_strtod): add test for bug fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b956b4a450
commit
b9bfdbb13e
3 changed files with 40 additions and 9 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Wed Jul 14 12:20:05 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
|
* util.c (ruby_strtod): should not convert string in the form of
|
||||||
|
"-I.FE-X" which both "I" and "F" are ommitted. [ruby-dev:23883]
|
||||||
|
|
||||||
|
* test/ruby/test_float.rb (test_strtod): add test for bug fix.
|
||||||
|
|
||||||
Wed Jul 14 01:20:21 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
Wed Jul 14 01:20:21 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
* array.c: rdoc patch - unified margin.
|
* array.c: rdoc patch - unified margin.
|
||||||
|
|
|
@ -61,12 +61,29 @@ class TestFloat < Test::Unit::TestCase
|
||||||
assert(a.abs < Float::EPSILON)
|
assert(a.abs < Float::EPSILON)
|
||||||
a = Float("-0.0")
|
a = Float("-0.0")
|
||||||
assert(a.abs < Float::EPSILON)
|
assert(a.abs < Float::EPSILON)
|
||||||
a = Float("0." + "00" * Float::DIG + "1")
|
a = Float("0.0000000000000000001")
|
||||||
assert(a != 0.0)
|
assert(a != 0.0)
|
||||||
a = Float("+0." + "00" * Float::DIG + "1")
|
a = Float("+0.0000000000000000001")
|
||||||
assert(a != 0.0)
|
assert(a != 0.0)
|
||||||
a = Float("-0." + "00" * Float::DIG + "1")
|
a = Float("-0.0000000000000000001")
|
||||||
assert(a != 0.0)
|
assert(a != 0.0)
|
||||||
|
a = Float(".0")
|
||||||
|
assert(a.abs < Float::EPSILON)
|
||||||
|
a = Float("+.0")
|
||||||
|
assert(a.abs < Float::EPSILON)
|
||||||
|
a = Float("-.0")
|
||||||
|
assert(a.abs < Float::EPSILON)
|
||||||
|
a = Float("0.")
|
||||||
|
assert(a.abs < Float::EPSILON)
|
||||||
|
a = Float("+0.")
|
||||||
|
assert(a.abs < Float::EPSILON)
|
||||||
|
a = Float("-0.")
|
||||||
|
assert(a.abs < Float::EPSILON)
|
||||||
|
assert_raise(ArgumentError){Float(".")}
|
||||||
|
assert_raise(ArgumentError){Float("+")}
|
||||||
|
assert_raise(ArgumentError){Float("+.")}
|
||||||
|
assert_raise(ArgumentError){Float("-")}
|
||||||
|
assert_raise(ArgumentError){Float("-.")}
|
||||||
# add expected behaviour here.
|
# add expected behaviour here.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
19
util.c
19
util.c
|
@ -722,7 +722,8 @@ ruby_strtod(string, endPtr)
|
||||||
* fractional part of the mantissa, and X
|
* fractional part of the mantissa, and X
|
||||||
* is the exponent. Either of the signs
|
* is the exponent. Either of the signs
|
||||||
* may be "+", "-", or omitted. Either I
|
* may be "+", "-", or omitted. Either I
|
||||||
* or F may be omitted, or both. The decimal
|
* or F may be omitted, but both cannot be
|
||||||
|
* ommitted at once. The decimal
|
||||||
* point isn't necessary unless F is present.
|
* point isn't necessary unless F is present.
|
||||||
* The "E" may actually be an "e". E and X
|
* The "E" may actually be an "e". E and X
|
||||||
* may both be omitted (but not just one).
|
* may both be omitted (but not just one).
|
||||||
|
@ -745,7 +746,8 @@ ruby_strtod(string, endPtr)
|
||||||
* case, fracExp is incremented one for each
|
* case, fracExp is incremented one for each
|
||||||
* dropped digit. */
|
* dropped digit. */
|
||||||
int mantSize = 0; /* Number of digits in mantissa. */
|
int mantSize = 0; /* Number of digits in mantissa. */
|
||||||
int decPt = FALSE; /* mantissa has decimal point. */
|
int hasPoint = FALSE; /* Decimal point exists. */
|
||||||
|
int hasDigit = FALSE; /* I or F exists. */
|
||||||
const char *pMant; /* Temporarily holds location of mantissa
|
const char *pMant; /* Temporarily holds location of mantissa
|
||||||
* in string. */
|
* in string. */
|
||||||
const char *pExp; /* Temporarily holds location of exponent
|
const char *pExp; /* Temporarily holds location of exponent
|
||||||
|
@ -778,13 +780,13 @@ ruby_strtod(string, endPtr)
|
||||||
|
|
||||||
for ( ; c = *p; p += 1) {
|
for ( ; c = *p; p += 1) {
|
||||||
if (!ISDIGIT(c)) {
|
if (!ISDIGIT(c)) {
|
||||||
if (c != '.' || decPt) {
|
if (c != '.' || hasPoint) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
decPt = TRUE;
|
hasPoint = TRUE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (decPt) { /* already in fractional part */
|
if (hasPoint) { /* already in fractional part */
|
||||||
fracExp -= 1;
|
fracExp -= 1;
|
||||||
}
|
}
|
||||||
if (mantSize) { /* already in mantissa */
|
if (mantSize) { /* already in mantissa */
|
||||||
|
@ -794,6 +796,7 @@ ruby_strtod(string, endPtr)
|
||||||
mantSize += 1;
|
mantSize += 1;
|
||||||
pMant = p;
|
pMant = p;
|
||||||
}
|
}
|
||||||
|
hasDigit = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -812,7 +815,11 @@ ruby_strtod(string, endPtr)
|
||||||
fracExp += (mantSize - 18);
|
fracExp += (mantSize - 18);
|
||||||
mantSize = 18;
|
mantSize = 18;
|
||||||
}
|
}
|
||||||
{
|
if (!hasDigit) {
|
||||||
|
fraction = 0.0;
|
||||||
|
p = string;
|
||||||
|
}
|
||||||
|
else {
|
||||||
int frac1, frac2;
|
int frac1, frac2;
|
||||||
frac1 = 0;
|
frac1 = 0;
|
||||||
for ( ; mantSize > 9; mantSize -= 1) {
|
for ( ; mantSize > 9; mantSize -= 1) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue