>>>>> "A" == Aristarkh A Zagorodnikov <xm / w3d.ru> writes: A> xm@is:~/build/ruby$ diff numeric.c numeric.c.orig A> 226,229c226 A> < if ((d1 = modf(value, &d2)) == 0) { A> < fmt = "%.1f"; A> < } A> < else if (value < 1.0e-3) { A> --- >> if (value < 1.0e-3) { A> 240a238,240 >> else if ((d1 = modf(value, &d2)) == 0) { >> fmt = "%.1f"; >> } Same problem with ruby -e 'p -0.01' but with your patch, it exist a possible buffer overflow (buf) pigeon% diff -u numeric.c.old numeric.c --- numeric.c.old Sat Sep 8 14:43:22 2001 +++ numeric.c Sat Sep 8 14:50:16 2001 @@ -223,7 +223,10 @@ else if(isnan(value)) return rb_str_new2("NaN"); - if (value < 1.0e-3) { + if ((d1 = modf(value, &d2)) == 0) { + fmt = "%.1f"; + } + else if (value < 1.0e-3) { d1 = value; while (d1 < 1.0) d1 *= 10.0; d1 = modf(d1, &d2); @@ -235,9 +238,6 @@ d1 = modf(d1, &d2); if (d1 == 0) fmt = "%.1e"; } - else if ((d1 = modf(value, &d2)) == 0) { - fmt = "%.1f"; - } sprintf(buf, fmt, value); return rb_str_new2(buf); pigeon% example pigeon% ruby -e 'p -123456789012345678901234567890.0' -e:1: [BUG] Segmentation fault ruby 1.7.1 (2001-09-05) [i686-linux] Aborted pigeon% Proposed patch (someone can verify it ?) pigeon% diff -u numeric.c.old numeric.c --- numeric.c.old Sat Sep 8 14:43:22 2001 +++ numeric.c Sat Sep 8 14:52:38 2001 @@ -223,13 +223,8 @@ else if(isnan(value)) return rb_str_new2("NaN"); - if (value < 1.0e-3) { - d1 = value; - while (d1 < 1.0) d1 *= 10.0; - d1 = modf(d1, &d2); - if (d1 == 0) fmt = "%.1e"; - } - else if (value >= 1.0e10) { + value = fabs(value); + if (value >= 1.0e10) { d1 = value; while (d1 > 10.0) d1 /= 10.0; d1 = modf(d1, &d2); @@ -238,7 +233,13 @@ else if ((d1 = modf(value, &d2)) == 0) { fmt = "%.1f"; } - sprintf(buf, fmt, value); + else if (value < 1.0e-3) { + d1 = value; + while (d1 < 1.0) d1 *= 10.0; + d1 = modf(d1, &d2); + if (d1 == 0) fmt = "%.1e"; + } + sprintf(buf, fmt, RFLOAT(flt)->value); return rb_str_new2(buf); } pigeon% pigeon% ruby -e 'p 0.0' 0.0 pigeon% ruby -e 'p -0.01' -0.01 pigeon% ruby -e 'p -123456789012345678901234567890.0' -1.23456789e+29 pigeon% Guy Decoux