Perhaps a Very Small Bug

Ross Paterson ross@soi.city.ac.uk
Thu, 28 Jun 2001 16:18:05 +0100


On Thu, Jun 28, 2001 at 02:57:48PM +0100, Iain McNaughton wrote:
> I was using WinHugs as a calculator. From the main command prompt in
> WinHugs, I typed the following:
> 
>  102.0*201.0 + 103.0*202.0 + 102.0*201.0 +102.0*202.0 + 102.5*200.5 
> 
> I then hit 'return', and was presented with the answer:
> 
>  102965.0

Indeed, you get that answer if you type 102965.25, which is somewhat
confusing.  Hugs is converting this to a string with sprintf %g,
which yields "102965".  It can't print that out because it looks
like an Int, so it appends ".0".  This only happens if there are
6 digits before the decimal point.  (It also does changes 4e+5 to
4.0e+5, but that can't go wrong like this.)

All this is in floatToString in machdep.c.  A hack-around is to change
the line

    if (buffer1[i]!='.') {

to

    if (buffer1[i]=='\0') {
        sprintf(buffer1,"%.1f",fl);
        i = j = 0;
    } else if (buffer1[i]!='.') {