Issues when applying a formula

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 corresponding Java’s Math class version:

final double a = 6378388;
final double b = 6356911.94613d;

final double ab = Math.sqrt(a*a - b*b);

final double e1 = ab / a; 
println("e1 =", e1);

final double e2 = ab / b; 
println("e2 =", e2);

4 Likes