Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: integer to string conversion Keywords: code Message-ID: <9675@alice.UUCP> Date: 24 Jul 89 19:35:44 GMT References: <3020@ohstpy.mps.ohio-state.edu> <9813@csli.Stanford.EDU> <9814@csli.Stanford.EDU> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 15 In article <9814@csli.Stanford.EDU>, poser@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@europa.att.com