diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-09-08 14:06:14 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-09-08 14:06:14 +0000 |
commit | b12951c688e541308bd3869470cd751c159091c3 (patch) | |
tree | bd16ae067aa231ed4d8ef1f70e47e91d6c7f80e0 /numeric.c | |
parent | 3081543be9a6b8b78839b79903cc1e87115e1a5a (diff) |
* eval.c (rb_thread_restore_context): save current value of
lastline and lastmatch in the thread struct for later restore.
* eval.c (rb_thread_save_context): restore lastline and lastmatch.
* numeric.c (flo_to_s): should handle negative float value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -210,21 +210,25 @@ flo_to_s(flt) char buf[24]; char *fmt = "%.10g"; double value = RFLOAT(flt)->value; - double d1, d2; + double avalue, d1, d2; if (isinf(value)) return rb_str_new2(value < 0 ? "-Infinity" : "Infinity"); else if(isnan(value)) return rb_str_new2("NaN"); - if (value < 1.0e-3) { - d1 = value; + avalue = fabs(value); + if (avalue == 0.0) { + fmt = "%.1f"; + } + else if (avalue < 1.0e-3) { + d1 = avalue; while (d1 < 1.0) d1 *= 10.0; d1 = modf(d1, &d2); if (d1 == 0) fmt = "%.1e"; } - else if (value >= 1.0e10) { - d1 = value; + else if (avalue >= 1.0e10) { + d1 = avalue; while (d1 > 10.0) d1 /= 10.0; d1 = modf(d1, &d2); if (d1 == 0) fmt = "%.1e"; |