Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!rutgers!att!cbnewsm!mnc From: mnc@cbnewsm.ATT.COM (michael.n.condict) Newsgroups: comp.lang.c Subject: Re: checking for overflow in C Summary: overflow is not a programmer error Message-ID: <436@cbnewsm.ATT.COM> Date: 9 May 89 03:42:05 GMT References: <13367@dartvax.Dartmouth.EDU> <10218@smoke.BRL.MIL> Organization: AT&T Bell Laboratories Lines: 26 In article <10218@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes: > In article <13367@dartvax.Dartmouth.EDU> shallit@eleazar.dartmouth.edu (Jeffrey Shallit) writes: > >... enlighten me about the officially approved way of checking overflow when > >multiplying two integers. > > Patient: Doctor, it hurts when I do this. > Doctor: Don't do that! > > You're looking for tactics when what is needed is better strategy. > How did you get your algorithm into the state where an overflow is > even possible? Sounds to me like the algorithm needs to be better > engineered. I think you're off-base here, Doug. The obvious (and morally justifiable) answer to your question is that you've read two numbers from the user's input and the user requests you to multiply them. A typical example would be an interpreter for a language that is using the local machine integers as its integer type. I too am interested in knowing how such an interpreter, written in portable C, can efficiently determine whether overflow will occur when it multiplies two arbitrary integers. The methods that come to my mind require much more time than the multiply itself. Please enlighten. Michael Condict AT&T Bell Laboratories Murray Hill, NJ {allegra|att}!m10ux!mnc