# Is it possible higher precision than double?

**URL:** <https://discourse.processing.org/t/is-it-possible-higher-precision-than-double/13764>\
**Category:** Beginners\
**Created:** [September 2, 2019, 12:01pm UTC](https://discourse.processing.org/t/is-it-possible-higher-precision-than-double/13764 "2019-09-02T12:01:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AngelRF](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@AngelRF](https://discourse.processing.org/u/AngelRF)\
**Post date:** [September 2, 2019, 12:01pm UTC](https://discourse.processing.org/t/is-it-possible-higher-precision-than-double/13764/1 "2019-09-02T12:01:28Z")

</div>

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. [https://en.wikipedia.org/wiki/Numerical\_differentiation](https://en.wikipedia.org/wiki/Numerical_differentiation)

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?

---

<div class="post-metadata">

**Author:** ![clankill3r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/clankill3r/32/1098_2.png) [@clankill3r](https://discourse.processing.org/u/clankill3r)\
**Post date:** [September 2, 2019, 12:14pm UTC](https://discourse.processing.org/t/is-it-possible-higher-precision-than-double/13764/2 "2019-09-02T12:14:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [September 2, 2019, 12:38pm UTC](https://discourse.processing.org/t/is-it-possible-higher-precision-than-double/13764/3 "2019-09-02T12:38:02Z")

</div>

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

```auto
import java.math.BigDecimal;
import java.math.RoundingMode;

// https://docs.oracle.com/javase/8/docs/api/java/math/class-use/BigDecimal.html#java.math
// https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html

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

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 2, 2019, 1:24pm UTC](https://discourse.processing.org/t/is-it-possible-higher-precision-than-double/13764/4 "2019-09-02T13:24:29Z")

</div>

> [@AngelRF](#):
>
> I’m already using `double`,

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

[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html)

- `TAU` → `2 * Math.PI`
- `cos(PI)` → `Math.cos(Math.PI)`
- `-5.4` → `-5.4d`
- `1e3` → `1e3d`

---

<div class="post-metadata">

**Author:** ![AngelRF](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@AngelRF](https://discourse.processing.org/u/AngelRF)\
**Post date:** [September 2, 2019, 2:40pm UTC](https://discourse.processing.org/t/is-it-possible-higher-precision-than-double/13764/5 "2019-09-02T14:40:40Z")

</div>

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