开发者

Higher precision doubles and trigonometric functions in Java

开发者 https://www.devze.com 2023-03-26 08:59 出处:网络
According to IEEE the following doubles exist: MantissaExponent double 64bit:52 bit11 bit double 80bit:64 bit15 bit

According to IEEE the following doubles exist:

                Mantissa   Exponent  
double 64bit:       52 bit     11 bit  
double 80bit:       64 bit     15 bit  

In Java only the 64bit double can be directly stored in an instance variable. 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?

One could of course do something along the following lines:

public class DoubleExt {
    private long mantissa;
    private short exponent;
}开发者_JS百科

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? What about supporting a couple of plattforms and architectures?

Bye


I'm pretty sure primitives won't get you there, but the BigDecimal class is as good as it gets (for everything except trigonometry).

For trigonometric functions, however, you will have to resort to an external library, like APFloat (see this previous question).


Perhaps BigDecimal is an adequate way for you. But I believe it doesn't provide the full set of mathematic functions.

http://download.oracle.com/javase/1,5.0/docs/api/java/math/BigDecimal.html


The question is already 5 years old. Time to look around
whether there are some new candidates, maybe draw inspiraction
from other languages.

In Racket we find a BigFloat data type:
https://docs.racket-lang.org/math/bigfloat.html

The underlying library is GNU MPFR, a Java interface was started:
https://github.com/kframework/mpfr-java

Is this the only interface so far?

0

精彩评论

暂无评论...
验证码 换一张
取 消