mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* util.c (ruby_strtod): try to reduce errors using powersOf10
table. [ruby-dev:28644] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c606447c00
commit
7b724e750f
2 changed files with 36 additions and 21 deletions
|
|
@ -1,3 +1,8 @@
|
|||
Wed May 17 08:17:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* util.c (ruby_strtod): try to reduce errors using powersOf10
|
||||
table. [ruby-dev:28644]
|
||||
|
||||
Tue May 16 15:34:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* re.c (rb_reg_initialize): should not allow modifying literal
|
||||
|
|
|
|||
36
util.c
36
util.c
|
|
@ -684,6 +684,18 @@ ruby_getcwd()
|
|||
#define MDMINEXPT DBL_MIN_EXP
|
||||
#define MDMAXEXPT DBL_MAX_EXP
|
||||
|
||||
static double powersOf10[] = { /* Table giving binary powers of 10. Entry */
|
||||
10.0, /* is 10^2^i. Used to convert decimal */
|
||||
100.0, /* exponents into floating-point numbers. */
|
||||
1.0e4,
|
||||
1.0e8,
|
||||
1.0e16,
|
||||
1.0e32,
|
||||
1.0e64,
|
||||
1.0e128,
|
||||
1.0e256
|
||||
};
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
|
|
@ -724,7 +736,7 @@ ruby_strtod(string, endPtr)
|
|||
* address here. */
|
||||
{
|
||||
int sign, expSign = Qfalse;
|
||||
double fraction = 0.0, dblExp;
|
||||
double fraction = 0.0, dblExp, *d;
|
||||
register const char *p;
|
||||
register int c;
|
||||
int exp = 0; /* Exponent read from "EX" field. */
|
||||
|
|
@ -891,19 +903,18 @@ ruby_strtod(string, endPtr)
|
|||
else {
|
||||
expSign = Qfalse;
|
||||
}
|
||||
dblExp = 10.0;
|
||||
while (exp) {
|
||||
dblExp = 1.0;
|
||||
for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
|
||||
if (exp & 01) {
|
||||
dblExp *= *d;
|
||||
}
|
||||
}
|
||||
if (expSign) {
|
||||
frac1 /= dblExp;
|
||||
}
|
||||
else {
|
||||
frac1 *= dblExp;
|
||||
}
|
||||
}
|
||||
exp >>= 1;
|
||||
dblExp *= dblExp;
|
||||
}
|
||||
exp = fracExp;
|
||||
if (exp < 0) {
|
||||
expSign = Qtrue;
|
||||
|
|
@ -912,19 +923,18 @@ ruby_strtod(string, endPtr)
|
|||
else {
|
||||
expSign = Qfalse;
|
||||
}
|
||||
dblExp = 10.0;
|
||||
while (exp) {
|
||||
dblExp = 1.0;
|
||||
for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
|
||||
if (exp & 01) {
|
||||
dblExp *= *d;
|
||||
}
|
||||
}
|
||||
if (expSign) {
|
||||
frac2 /= dblExp;
|
||||
}
|
||||
else {
|
||||
frac2 *= dblExp;
|
||||
}
|
||||
}
|
||||
exp >>= 1;
|
||||
dblExp *= dblExp;
|
||||
}
|
||||
fraction = frac1 + frac2;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue