integer to string conversion

Andrew Koenig ark at alice.UUCP
Tue Jul 25 05:35:44 AEST 1989


In article <9814 at csli.Stanford.EDU>, poser at csli.Stanford.EDU (Bill Poser) writes:

> It is correct that the routine I posted doesn't do the right thing on the
> most negative integer. That requires a special case, which I left out.

It is possible to do it without special cases, at least for
a very wide range of machines.  For example, every machine
I've ever seen allows you to flip the sign of the most positive
integer without overflow.  This suggests using negative numbers
for all your intermediate results.  If you do that, be careful
to defend against machines that round toward -infinity
rather than toward zero when doing integer division.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list