[net.lang.c++] oct, dec, hex, and unsignedness

jim@umcp-cs.UUCP (Jim Williams) (09/08/86)

In article <6021@alice.uUCp> bs@alice.UucP (Bjarne Stroustrup) writes:

>Maybe there ought to be a separate function ``unsig()'' like the ``oct()''
>and ``hex()'' functions, but currently there is not.

I think that adding arguments to existing functions would be better
than adding functions. i.e.

	hex(0xFFFFFFFF, 0, UNSIGNED) 

would produce "FFFFFFFF", but

	hex(0xFFFFFFFF, 0, SIGNED) would produce

"-1".  I prefer this solution to adding functions, since it can be 
general, and can be used with oct, and dec, and any new functions
people think up. SIGNED and UNSIGNED can be implemented in several
ways, and would be defined in stream.h.   This solution also allows
each function to choose what its default would be.  I imagine dec()
having a default of SIGNED, whereas hex(), and oct() would have 
UNSIGNED as default.
 
By the way, the current inplementation of dec() will not print the 
most negative long integer correctly on a 2's complement machine.
(The first thing the code does is to change a negative argument into
a positive one, and set a sign flag.  This is a big lose on a 2's
complement machine!)

Also, the second argument to str() does NOT truncate the string
the way the other functions do.  If the string is too long it
just overflows, and makes it as long as it has to be (which is
what an argument of 0 does).  I definitely consider this a bug.
Do you consider it feature?


-- 
Jim \/\/illiams
jim@mimsy.umd.edu
umcp-cs!jim.UUCP