j4n bur53 j4n bur53 - 1 month ago 10
Java Question

Higher precision doubles and trigonometric functions in Java

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;
}


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

Answer

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).

Comments