Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Joshua Cranmer Newsgroups: comp.lang.java.programmer Subject: Re: Arithmetic overflow checking Date: Mon, 11 Jul 2011 14:49:52 -0700 Organization: A noiseless patient Spider Lines: 13 Message-ID: References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <1f9c17dltrhlmhifuigoa914477r4rg1e1@4ax.com> <658108b9-3fa9-41dd-8701-9f342633864c@x12g2000yql.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 11 Jul 2011 21:49:54 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="Q8HyEFb0j2lB0WC1MU3ArQ"; logging-data="25999"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cjKwmjJKj+s7fh+RWszfzfE6HE9N2erY=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11 In-Reply-To: Cancel-Lock: sha1:lkzn7VHmpnL1YjBvw4iV7XU8BJQ= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6086 On 7/11/2011 2:43 PM, Gene Wirchenko wrote: > On Mon, 11 Jul 2011 10:30:26 -0700, Joshua Cranmer > wrote: > Averaging a set of numbers with a sum too big would be caught by > overflow checking and not bounds checking. What I advocated would basically be a "checked integer": every operation is guaranteed to have a result between [min, max]; if not, it throws an exception. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth