Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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: Sat, 06 Aug 2011 16:51:18 -0500 Date: Sat, 06 Aug 2011 14:51:21 -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: higher precision doubles References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 62 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.203.65 X-Trace: sv3-JsjLtTIb7FhuwiluDN9o4iZMI5YmziLMvL2jl9fVjHSy1d8zZwLVBUISqPDxhTwkz5HWQ3+waBI+tqm!Vh2bS3jq4jQk7uAdhRj1atsSw8yA+Q90T4WNxkAUD38N7be3iZJnan4YjVpjwo3X7xOgKieZpeFA!melyYsDkeiXuR4Mk1xVLn5DLfGZbO125Ve2BYtBaclD7Dw== 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: 3166 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6834 On 8/6/2011 12:24 PM, Jan Burse wrote: > Stefan Ram schrieb: >> Jan Burse writes: >>> IEEE allows to internally calculate with additional bits. >>> Is it possible to have awailable these ops? Like an add >>> with this higher precision? How could we store such a >>> result? Would there be a wrapper like Double? >> >> See also: >> >> http://en.wikipedia.org/wiki/Strictfp >> >> . >> > > Motivating example, in Go we have: > > func main() { > x := math.Sin(2*math.Pi) > fmt.Printf("x = %.30f, is zero = %v\n", x, x == 0) > } > > x = 0.000000000000000000000000000000, is zero = true > > In Java we have: > > > public static double zero1() { > return Math.sin(2*Math.PI); > } > > public static double zero2() { > return StrictMath.sin(2*StrictMath.PI); > } > > public static void main(String[] args) { > System.out.println("zero1="+zero1()); > System.out.println("zero2="+zero2()); > } > > zero1=-2.4492935982947064E-16 > zero2=-2.4492935982947064E-16 I'm not sure I understand how this motivates extra precision. Would you have been happier if the result had been something order 10^-24? Or if this particular calculation had got 0, but some other even multiple of PI had got an order 10^-24 result? There are two issues here, algorithm and arithmetic precision. I do not know exactly how Java calculates sin, but the usual approach is to have a polynomial approximation for a range of angles close to zero, and a reduction algorithm that maps calculating the sin of a general angle to calculating the sin of an angle in that range (possibly with a need to negate the result). In this case the difference is most likely in the reduction step - if it had produced 0, the sin result would have been 0. Without a change in the algorithm, or its objective, I do not think extra precision would eliminate all cases of this sort of difference. Patricia