🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c++
Article #302

oct, dec, hex, and unsignedness

#302
From: Jim Williams
Date: Mon, 08 Sep 1986 18:51
39 lines
2060 bytes
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
Technical Details
Message-ID: <3333@umcp-cs.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!umcp-cs!jim
References: <6021@alice.uUCp>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!umcp-cs!jim
From: jim@umcp-cs.UUCP (Jim Williams)
Newsgroups: net.lang.c++
Subject: oct, dec, hex, and unsignedness
Message-ID: <3333@umcp-cs.UUCP>
Date: Mon, 8-Sep-86 14:51:58 EDT
Article-I.D.: umcp-cs.3333
Posted: Mon Sep  8 14:51:58 1986
Date-Received: Mon, 8-Sep-86 21:02:47 EDT
References: <6021@alice.uUCp>
Reply-To: jim@umcp-cs.UUCP (Jim Williams)
Organization: University of Maryland, Dept. of Computer Sci.
Lines: 39
Summary: add arguments, not functions