Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news.stack.nl!.POSTED!ipv6.urchin.earth.li!twic From: Tom Anderson Newsgroups: comp.lang.java.programmer Subject: Re: Arithmetic overflow checking Date: Sat, 9 Jul 2011 10:21:59 +0100 Organization: Stack Usenet News Service Lines: 37 Message-ID: References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <2rydnez7l-H5BYnTnZ2dnUVZ_vGdnZ2d@earthlink.com> <9LWdnZH2hdfmyYvTnZ2dnUVZ_vidnZ2d@posted.palinacquisition> NNTP-Posting-Host: ipv6.urchin.earth.li Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: mud.stack.nl 1310203320 50431 2001:ba8:0:1b4::6 (9 Jul 2011 09:22:00 GMT) X-Complaints-To: abuse@stack.nl NNTP-Posting-Date: Sat, 9 Jul 2011 09:22:00 +0000 (UTC) User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6012 On Fri, 8 Jul 2011, Eric Sosman wrote: > On 7/7/2011 8:51 PM, Peter Duniho wrote: > >> I would not worry about the "simple" or "efficient" criteria. IMHO, if >> one is deciding to apply overflow checking to every computation, one has >> already abandoned the hope of efficiency. > > I've used machines that raised overflow traps "for free," in > the sense that it was done by the hardware/firmware/microcode, just > like setting condition flags. > > Flipping the mode bit that enabled or disabled traps for integer > arithmetic was relatively expensive, so programs tended to set it > one way or the other during initialization and then just leave it > alone. But it's not necessary to use a global bit to get this kind > of behavior: an instruction set might feature both an AddAndWrap and > an AddAndTrap instruction. True, that's not entirely free -- you > pay for extra decoding logic in the instruction pipeline, for example. > But the inefficiencies don't rise to the "abandon hope" level, IMHO. > > Besides: What are the relative efficiencies of an error caught > and announced versus a wrong answer computed at great speed without > any indication that it's wrong? > > (The machines I speak of were from forty-odd years ago and might be > dismissed as ancientry, but their lineal descendants are still being > made and sold. I don't know how today's editions deal with overflow, > but if you're curious you can write to the vendor. Their headquarters > are in Armonk, NY.) In that case, i can tell you what they do: charge you extra for it. tom -- ONE IN EIGHT GO MAD