# Problem sin() cos() Java to Processing 4.0

**URL:** https://discourse.processing.org/t/problem-sin-cos-java-to-processing-4-0/45567
**Category:** Beginners
**Created:** [January 10, 2025, 1:42am UTC](https://discourse.processing.org/t/problem-sin-cos-java-to-processing-4-0/45567 "2025-01-10T01:42:28Z")
**Posts on this page:** 1
**Showing post:** 4

<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: [January 10, 2025, 4:07pm UTC](https://discourse.processing.org/t/problem-sin-cos-java-to-processing-4-0/45567/4 "2025-01-10T16:07:19Z")

</div>

If you require high `double` precision, besides replacing Processing’s math functions w/ corresponding Java’s Math, avoid Processing’s constants like DEG\_TO\_RAD as well; b/c they’re `float` type, not `double`:

> <https://github.com/processing/processing4/blob/processing-1295-4.3.2/core/src/processing/core/PConstants.java#L210-L211>

```auto
final double DEG_TO_RAD_D = Math.PI / 180, RAD_TO_DEG_D = 180 / Math.PI;

final double phi = 43.95_13_81d, dist = 1.13d / 6_371_000, theta = 351.4d;

final double lat = Math.asin(
  Math.sin(phi * DEG_TO_RAD_D) * Math.cos(dist) +
  Math.cos(phi * DEG_TO_RAD_D) * Math.sin(dist) * Math.cos(theta * DEG_TO_RAD_D)
);

println(lat, lat * RAD_TO_DEG_D);

```

For further reading about `double` type in Processing/Java, go to this thread below:

> [@Issues when applying a formula](https://discourse.processing.org/t/issues-when-applying-a-formula/45520/2):
>
> Processing uses the 32-bit float primitive datatype as its default floating-point precision: For 64-bit floating-point precision we use double instead: However, it’s not enough to simply declare variables w/ primitive datatype double! We also must suffix any floating-point literal w/ a d, so it uses a 64-bit storage: 6356911.94613d Without it, 6356911.94613 would be coerced to 6356912.0 due to 32-bit storage constraint! Plus all Processing’s math functions need to be replaced w/ their co…

---

_[View the full topic](https://discourse.processing.org/t/problem-sin-cos-java-to-processing-4-0/45567)._
