Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 18 Jul 2011 18:36:19 -0500 Date: Mon, 18 Jul 2011 16:36:14 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Arithmetic overflow checking References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <1f9c17dltrhlmhifuigoa914477r4rg1e1@4ax.com> <658108b9-3fa9-41dd-8701-9f342633864c@x12g2000yql.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 31 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.200.239 X-Trace: sv3-AxzaXCDB4nNn2/p+ZIn4/dz+ffenkIy+LcLI4MpgbSIGRtJWUskNHzRyGeSp5zDibFCESvjAdx95UWa!YZKMLAXU6mT6+K9vwqbsb0/ETGNCte5giy9QqfBgzdD7+EFX1QAr3Vn/a+k+i6K5Vb0/vqUnfD7l!9waFsrhzHJWVwvoigpSeRVffm2YF7yuMhH+37txaWQpSfG0= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3239 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6272 On 7/18/2011 4:28 PM, David Lamb wrote: > On 17/07/2011 11:14 AM, Daniele Futtorovic wrote: >> On 11/07/2011 23:49, Joshua Cranmer allegedly wrote: >>> 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. >> >> Sounds cool. Any chance we might see it in teh Jav one day? And is there >> actually hardware support for it? > > I think the gist of some other discussion in this thread is that some > computers have hardware detection and others don't. In a sense, most processors that could run a full Java installation already have what they need. In many case, range limited integer checking can be done at compile time, because of the greater precision. Suppose, for example, you are adding two one digit numbers. If each of them is in a [0,9], the compiler knows that the result will fit in a [0,18]. If each is in a byte, the compiler cannot know that their sum fits in a byte. In the remaining cases, we are looking at comparisons involving constants and values that are already in registers, and conditional branches that go the same way somewhere between 99.9999% and 100% of the time. The expensive operations are cache misses and mis-predicted branches, and neither is likely in this case. The processor in a small 2011 PC is a supercomputer by historical standards, with the ability to do multiple operations at the same time, if the data is available. Patricia