[lug] setw(x) (in C++ standard library) on float or double seems to fail in RedHat7.

Tkil tkil at scrye.com
Mon Nov 13 20:43:11 MST 2000


hi, Bob.  :)

i assume you noticed the typo in this code?
>>>>> "Bob" == Robert George Mayer <mayer at acm.org> writes:

Bob>     cout << 15) << 0 << setw(15) << 1 << endl;
                 ^^^

Bob>     cout << setw(15) << 0.0 << setw(15) << 1.0 << endl;

this should be the same as the double example (ZERO and ONE, to use
your declarations aboves) since floating-point constants are assumed
double unless marked as float.  (and yes, i had to look that one up.
:)

let me try a more direct case with RH6.2, which is running:

| $ gcc -v
| Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
| gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

=============================================================================
#include <iostream>
using std::cout;

#include <iomanip>
using std::endl;
using std::setw;

int main()
{
    cout << "         ....+....+....|....+....+....|"           << endl
	 << "int:     " << setw(15) << 0    << setw(15) << 1    << endl
	 << "long:    " << setw(15) << 0L   << setw(15) << 1L   << endl
	 << "float:   " << setw(15) << 0.0F << setw(15) << 1.0F << endl
	 << "double:  " << setw(15) << 0.0  << setw(15) << 1.0  << endl;
  
    return 0;
}
=============================================================================

which gives:

| $ make bob
| g++     bob.cc   -o bob
| $ ./bob
|          ....+....+....|....+....+....|
| int:                   0              1
| long:                  0              1
| float:                 0              1
| double:                0              1

which is what we expect.  hm... now to find a system with the other
compiler on it.  thanks to kevin, we have:

| $ gcc -v
| Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
| gcc version 2.96 20000731 (Red Hat Linux 7.0)
| $ make bob
| g++     bob.cc   -o bob
| $ ./bob
|          ....+....+....|....+....+....|
| int:                   0              1
| long:                  0              1
| float:   01
| double:  01

so yes, i'd agree with you that this is a bug.  weird.  i'm
downloading the latest snapshot now.  oh yeah, there's a
compile-and-see-what-happens tool on the codesourcery site.  maybe we
can have fun with it...

t.




More information about the LUG mailing list