Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Joshua Cranmer Newsgroups: comp.lang.java.programmer Subject: Re: Java puzzler Date: Sat, 14 May 2011 23:43:38 -0400 Organization: A noiseless patient Spider Lines: 27 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 03:43:40 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="3xSaU6y5tAyBQEIxw+DaTw"; logging-data="11570"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JFkLcXfbRAKHUxlg4Bd892AGjzeqrTYw=" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.16pre) Gecko/20110305 Lightning/1.0b3pre Thunderbird/3.1.10pre In-Reply-To: Cancel-Lock: sha1:wt/5QsQT7GIH6VuOT1y5DTRJZ9w= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4103 On 05/14/2011 09:35 PM, markspace wrote: > What I'm saying is: at the machine level, the implementation is free to > throw an excpetion if any intermediate calculation overflows. I think > that's the difference between "infinite precision" and saying the > compiler and optimizer have some latitude. The problem with that is that the result becomes unpredictable. If the compiler deems it optimizable, the code would cease to throw an exception, which means the context in which the code runs drastically changes its execution. C gets around this issue by declaring what happens in overflow undefined (hence, the compiler can legally do whatever it wants, including formatting your hard drive). In some ways, Java skirts the issue in floating point by declaring floating point operations to be able to use higher-precision if available (in essence, implicitly permitting higher-level floating point optimizations), unless you need the strict guarantees of IEEE 754, which you can obtain via strictfp. Of course, the problem with this whole approach is that people might depend on the precise overflow semantics, only to find that the machine optimizes out the possibility of overflow. This, too, can lead to problems... so does it really buy you anything? -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth