Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: BGB Newsgroups: comp.lang.java.programmer Subject: Re: higher precision doubles Date: Mon, 08 Aug 2011 13:49:58 -0700 Organization: albasani.net Lines: 53 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net N3RhfiA7CEViQObM29Qh0fkfDpFBFe19SBoLkTlRahhyn+yFE15jj81tKdyo3CorzqkvU3uakamXHIwX17q787NOUXy6MxaM2vb12qX451c3a4tKxMpxW073xLXRMiDr NNTP-Posting-Date: Mon, 8 Aug 2011 20:54:56 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="tLMD6524YZ4dHVqnKzORgEJSN9eUpAtWT5voFoN4OniLqAVl7BWiRZMdUTSj8gk+wzBdXFUwbuIwabTZdASVeR8GduBeWdAn9PjM+SK7CPzg3yY2HeIjLRkt1wSv05LE"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: Cancel-Lock: sha1:hsNTeMzqLhnFf5I63f3vdKPv0jc= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6877 On 8/8/2011 12:05 AM, Jan Burse wrote: > Eric Sosman schrieb: >>> I would like for whatever reason work with 80bit >>> floats as defined above in Java. I am interested >>> in the full set of arithmetic functions, I/O and >>> trigonometric functions. How could I do that? >> >> You have already said "So pointing me to JLS is like turning >> cycles, only confirming that Java has only float and double." That >> is, the JLS has already given you an answer -- but you don't like >> the answer, and keep asking for a different one. Do you really >> think your persistent rejection of "No" is productive? > > > You are the first one that says "no". One could of > course do something along the following lines: > > public class DoubleExt { > private long mantissa; > private short exponent; > } > > And then make a package that interfaces with some > of the known C libs for 80bit floats. > > But would this be considered the best practice? > actually, if you really want 80-bit floats in Java, you can use the above as a starting point (just add a boolean or similar for the sign), and proceed to implement the rest directly in Java (calling into C would also work, and probably be more efficient, but JNI or JNA add their own levels of pain, among other issues...). addition and subtraction are mostly just shifting and adding and similar (some fudging required). multiplication is mostly doing a 128-bit integer multiply and discarding the low 64 bits, adding the exponents. there are ways to "cheat" (avoiding performing a 128-bit multiply) but these cost accuracy (some fudging required, as the output of z=1.x*1.y is in the range of 1<=z<4). division is mostly calculating the reciprocal of the second value, and multiplying the first by this (can be done using Newton's Method). square root is, again, Newton's Method. the trigonometric functions can, in turn, be implemented using the Taylor Series (building on the former arithmetic operators). yes, these operations are not exactly necessarily "fast"...