Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Java puzzler Date: Sun, 15 May 2011 05:40:15 -0700 Organization: A noiseless patient Spider Lines: 32 Message-ID: References: <4db69c13-878f-4806-adb2-a3c5adb1c48c@glegroupsg2000goo.googlegroups.com> <-8mdnSRPEIdA21HQnZ2dnUVZ_j2dnZ2d@earthlink.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 15 May 2011 12:40:20 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="Gyo0FQiuGFjMddvl0JJHxw"; logging-data="10266"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MzszReL3VwoIYbw1nJ6aTA8e9u2UeMJw=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:WuayrVR8x5dSVQytENATUBaGltQ= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4113 On 5/15/2011 3:16 AM, Tom Anderson wrote: > Fair enough. I suppose my position is that this hardware ability has to > be used in the service of some solidly well-defined software semantics. > Throwing exceptions at random from arithmetic expressions is not what i > think of as solidly well-defined. I guess I'm not understanding what people think is wrong with the semantics of "overflow." Overflow is very well defined. It's something like 8 gates on the hardware level, and happens at the same speed as the the add or subtract itself. I.e., about 1 CPU cycle in most cases nowadays. By contrast, the current semantics of integer math are that sometimes you get the right answer and sometimes you don't. I consider that to be non-deterministic. Here's a method to sum a list of numbers: public int sum( int[] nums ) { int sum = 0; for( int n : nums ) sum += n; return sum; } What I want is for this to throw an error if it can't compute the sum correctly. How is that non-semantic, even slightly? How is the current implementation where sometimes this works and sometimes it doesn't even *slightly* semantic in comparison?