0

I am looking for a way of storing really precise and also really large numbers in java. I want something like a double, but ideally with a few hundred bytes instead of only 8. I would like to be able to evaluate trig functions and things more complicated than basic arithmetic with this level of accuracy.

This isn't that important, but I would like to know if this is possible.

  • 4
    http://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html – Marvin Mar 23 '17 at 22:04
  • 1
    **Yes**. [`BigDecimal`](http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html). – Elliott Frisch Mar 23 '17 at 22:04
  • 1
    [`BigInteger`](http://stackoverflow.com/documentation/java/1514/biginteger#t=201703232203535355597) for big integers. [`BigDecimal`](http://stackoverflow.com/documentation/java/1667/bigdecimal#t=201703232204255361422) for arbitrarily precise floating point numbers. – RaminS Mar 23 '17 at 22:04
  • BigDecimal is your best friend :). The only limit now is your RAM. – Ousmane D. Mar 23 '17 at 22:05
  • 2
    There's no built-in support for trig functions with `BigDecimal`, though. – Louis Wasserman Mar 23 '17 at 22:12
  • See Question: [Java BigDecimal trigonometric methods](http://stackoverflow.com/q/2173512/642706) – Basil Bourque Mar 23 '17 at 22:40

1 Answers1

-2

You can use BigInteger or BigDecimal. I recomend use BigInteger just because in Java 8 it has been made a mayor improvements in that class.

Regards

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Augusto
  • 89
  • 6
  • 1
    How would you store _something like a double_ as BigInteger? – Marvin Mar 23 '17 at 22:07
  • I need decimals, bigInteger can hold large enough values, but big decimal is still limited since it can't change the number of significant figures. One problem is also that java's sin() and cos() and pow(), etc, functions aren't nearly precise enough. I know a way I could do this with a lot of difficulty, but I guess what I'm really wondering is if someone has made a library to do this. – Information Aether Mar 23 '17 at 22:34
  • 3
    @OusmaneMahyDiaw Since when do Comments trump Answers on Stack Overflow? Please cite documentation for this major policy change. – Basil Bourque Mar 23 '17 at 22:42