Is it possible higher precision than double?

I’m doing a Numeric Differentiation calculating program, and the second and third derivative get waay too noisy, according to wikipedia, this is caused by floating-point arithmetic rounding.

Wikipedia says that noise can be reduced by increasing floating-point datatype precision.
I’m already using double, but in Processing reference there isn’t a preciser datatype than double.

Is there any possible way to get more precise datatype?

Google java BigDecimal, it’s a class and a pain to work with (compared to how we would do it normally), but it should do the job. There is also BigInteger.
Keep in mind they are both slow.

1 Like

i play here, but was just too slow for @clankill3r

import java.math.BigDecimal;
import java.math.RoundingMode;


float af =2;
float bf =3;
float resultf;
double ad=2d;
double bd=3d;
double resultd;
BigDecimal abd = BigDecimal.valueOf(ad);
BigDecimal bbd = BigDecimal.valueOf(bd);
BigDecimal resultb= new BigDecimal("0");

resultf = af/bf;
resultd = ad/bd;
resultb = abd.divide(bbd,20, RoundingMode.HALF_EVEN);

println("resultf "+resultf);
println("resultd "+resultd);
println("resultb "+resultb);

Make sure to use constants & methods from Math class only and all non-integer numerical literals are suffixed w/ d: :warning:

  • TAU2 * Math.PI
  • cos(PI)Math.cos(Math.PI)
  • -5.4-5.4d
  • 1e31e3d

So much thanks to you guys :slight_smile:, but may be I will have to do serious optimization