From: Ken Thompson Date: Sat, 5 Jul 2008 01:01:35 +0000 (-0700) Subject: floating point print X-Git-Tag: weekly.2009-11-06~3561 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ac5a887d5d638657f2759235987c4e93bd13c213;p=gostls13.git floating point print SVN=126038 --- diff --git a/src/runtime/print.c b/src/runtime/print.c index ebc461bc46..46ecda80d6 100644 --- a/src/runtime/print.c +++ b/src/runtime/print.c @@ -49,7 +49,63 @@ sys·printbool(bool v) void sys·printfloat(float64 v) { - sys·write(1, "printfloat", 10); + byte buf[20]; + int32 e, s, i, n; + float64 h; + + n = 5; // digits printed + e = 0; // exp + s = 0; // sign + if(v != 0) { + // sign + if(v < 0) { + v = -v; + s = 1; + } + + // normalize + while(v >= 10) { + e++; + v /= 10; + } + while(v < 1) { + e--; + v *= 10; + } + + // round + h = 5; + for(i=0; i= 10) { + e++; + v /= 10; + } + } + + // format +d.dddd+edd + buf[0] = '+'; + if(s) + buf[0] = '-'; + for(i=0; i