From: matz@... (Yukihiro Matsumoto) Date: 2001-09-08T22:46:50+09:00 Subject: [ruby-talk:20998] Re: Bug in latest snapshot, regarding Float#to_s Hi, In message "[ruby-talk:20994] Bug in latest snapshot, regarding Float#to_s" on 01/09/08, "Aristarkh A Zagorodnikov" writes: | Recently I installed the latest snapshot (ruby 1.7.1 (2001-09-03) |[i686-linux]), and after some time of work found that it has a bug. After 2 |hours of tracing the bug (all started from random Apache hangs), I traced it |down to Float#to_s and discovered that "ruby -e 'p 0.0'" puts computer in |and endless loop. The following patch to numeric.c (by no means said to be |100% correct or extensively tested) fixed the situation for me. Here's my patch: diff -u -1 -r1.30 numeric.c --- numeric.c 2001/09/03 05:37:42 1.30 +++ numeric.c 2001/09/08 13:46:23 @@ -218,3 +218,3 @@ double value = RFLOAT(flt)->value; - double d1, d2; + double avalue, d1, d2; @@ -225,4 +225,8 @@ - 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; @@ -231,4 +235,4 @@ } - else if (value >= 1.0e10) { - d1 = value; + else if (avalue >= 1.0e10) { + d1 = avalue; while (d1 > 10.0) d1 /= 10.0;