2

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

  • are you talking about something like strictfp class? – Sumit Aug 08 '11 at 09:19
  • There is a class StrictMath which implements the 64bit double. But I am asking for 80bit double. I also noticed a similar question here: http://stackoverflow.com/questions/277309/java-floating-point-high-precision-library But I am especially interested also of a coverage of trigonometric functions. –  Aug 08 '11 at 09:20

3 Answers3

1

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

Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • I didn't see some trigonometric functions in BigDecimal. But otherwise with a custom MathContext, this would probably do. –  Aug 08 '11 at 09:22
  • Ok, I see there is a ApfloatMath.sin for example. Ok, have to check. –  Aug 08 '11 at 09:28
0

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

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

martin
  • 2,957
  • 3
  • 25
  • 46