Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: Re: higher precision doubles Date: Tue, 09 Aug 2011 14:00:23 +0200 Organization: albasani.net Lines: 36 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net nMB3pEAYiDdxugiwPE8vixir2Yoj+P3DKp2bKi7GQerW/QiKU8IiesPcMB4sA8UNdX+0qlfQa5/NWdw6EarXHA== NNTP-Posting-Date: Tue, 9 Aug 2011 12:00:23 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="+YeDNt7vCH3LBEmeLZ3Mevn81IXhN7N6yYa9CXbOl1I832Jgrgy76PY3MbImGOAdBVcSbK6qPT23BCDkfBKnDLiqkqr5Xa8kwwrr9qSJJj/50Wan13g6w/DMNy1S6p+i"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110706 Firefox/5.0 SeaMonkey/2.2 In-Reply-To: Cancel-Lock: sha1:5XXup5B9Mp4AAUv/FvLt6+zRokg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6911 Patricia Shanahan schrieb: > > My understanding when strictfp was being added was that the x86 > instruction set allowed for efficient rounding to the correct 32 and 64 > bit mantissa widths, but did not allow for the overflow and underflow > processing to be done based on the correct exponent widths. The typical overflow example is: double x = Double.MAX_VALUE * 1.1 / 1.1; When internally during an arithmetic expression evaluation long double is used, Double.MAX_VALUE * 1.1 can be fully represented thanks to the additional bits in mantissa AND exponent. And eventually we would get back Double.MAX_VALUE in x after rounding. When internally no long doubles are used, then Double.MAX_VAlUE*1.1 gives already +inf or somesuch. Since Java does not throw an exception, but is required to return some value. And then division by 1.1 does not help anymore. Another example is the following: float f = Float.MAX_VALUE; float g = Float.MAX_VALUE; doube x = f * g; https://www.securecoding.cert.org/confluence/display/java/NUM06-J.+Use+the+strictfp+modifier+for+floating-point+calculation+consistency+across+platforms The above document is a little bit sloppy, since it mentions only additional bits in the exponent. But 80bit doubles have both, additional bits in the mantissa and in the exponent. So differences might be more subtle. Bye