aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-09 01:57:49 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-09 01:57:49 +0000
commitc383fbf93f691f443eb16761351a6943bc29d3f9 (patch)
tree538fe8e31a85eb85a67ea1d1127dee2b9dc74fba /util.c
parentb3c7867df7cd186e73021f0ed9d17680999f190f (diff)
downloadruby-c383fbf93f691f443eb16761351a6943bc29d3f9.tar.gz
* util.c (ruby_strtod): this code uses FPU's rounding system.
But x86's FPU calculates double precision floating-point numbers in 80bit precision, so it fails to round the value. So ensure the value is assigned a variable. [ruby-dev:42551] see also [ruby-math:00802] http://www.shudo.net/java-grandprix99/strictfp/ git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/util.c b/util.c
index 0b69b6cfb7..bc307e4636 100644
--- a/util.c
+++ b/util.c
@@ -4014,10 +4014,13 @@ ruby_hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,
/* Round to the desired number of digits. */
if (SIGFIGS > ndigits && ndigits > 0) {
float redux = 1.0f;
+ volatile double d;
int offset = 4 * ndigits + DBL_MAX_EXP - 4 - DBL_MANT_DIG;
dexp_set(u, offset);
- u.d += redux;
- u.d -= redux;
+ d = u.d;
+ d += redux;
+ d -= redux;
+ u.d = d;
*decpt += dexp_get(u) - offset;
}