Article View: gnu.g++.lib.bug
Article #53strange behavior of the __outfloat routine
From: Christoph Tietz
Date: Mon, 20 Jul 1992 12:48
Date: Mon, 20 Jul 1992 12:48
51 lines
2531 bytes
2531 bytes
The following test program shows the different behavior of printf and
cout.form on the same numbers:
-------------------------------------------------------------------------------
// This may look like C code, but it is really -*- C++ -*-
#include <stream.h>
#include <stdio.h>
int main () {
printf ("Output for the format %%5.0f :\n");
printf ("printf : <%5.0f>\n", 10.0);
printf ("printf : <%5.0f>\n", 600.0);
printf ("printf : <%5.0f>\n", 2010.0);
printf ("printf : <%5.0f>\n", 10000.0);
cout << form ("cout.form: <%5.0f>\n", 10.0);
cout << form ("cout.form: <%5.0f>\n", 600.0);
cout << form ("cout.form: <%5.0f>\n", 2010.0);
cout << form ("cout.form: <%5.0f>\n", 10000.0);
}
-------------------------------------------------------------------------------
The problem seems to come up around line 107 in outfloat.C, where the number
of trailing zeroes is calculated and used to decide, whether a decimal point
should be printed. It seems to be neglected, that the precision given with e,
E and f-Formats denotes the number of digits to appear after the decimal
point and NOT the total number of significant digits. It may be connected to
the behavior of the expression: precision-(useful_digits-decpt) that gives
strange results, if decpt is greater than useful_digits.
>From there on numbers get out of line quite soon. In line 121 the unpadded
width is calculated wrongly because show_dot was set erroneously, and in line
155 then the trailing digits that were printed correctly before the decimal
point are repeated after the decimal point, giving the following quite
bizarre results:
Output for the format %5.0f :
printf : < 10>
printf : < 600>
printf : < 2010>
printf : <10000>
cout.form: < 10.0>
cout.form: < 600.00>
cout.form: <2010.0>
cout.form: <10000.0000>
I could not find a simple patch that would work for all possible floating
point formats so I can regrettably only state the problem here. Perhaps
somebody already has a fix??
Christoph Tietz
Technical Details
Message-ID:
<tietz.711636509@gmd.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!gmd.DE!tietzShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.lib.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!gmd.DE!tietz From: tietz@gmd.DE (Christoph Tietz) Subject: strange behavior of the __outfloat routine Message-ID: <tietz.711636509@gmd.de> Sender: gnulists@ai.mit.edu Organization: GMD, Sankt Augustin, Germany Distribution: gnu Date: Mon, 20 Jul 1992 12:48:29 GMT Approved: bug-lib-g++@prep.ai.mit.edu Lines: 52