I am currently writing a project for uni, and I was wondering if there are any good practices to be more precise with double values. Namely, is there any difference in precision if I write just a long expression directly in the return statement, or is it better if I split the expression into final
variables (making it also more readable, by the way)? For instance, imagine if I had the following formula: Math.sin(a) / Math.cos(b) + Math.tan(c) / d
; is it better to write it like follows?
final double sinA = Math.sin(a);
final double cosB = Math.cos(b);
final double tanC = Math.tan(c);
return sinA / cosB + tanC / d;
Thank you in advance!
BigDecimal
final
will just make sure that the variable cannot be assigned to after it is initialized (i.e. set to a value). For local variables that's mainly just to benefit maintenance / readability; it doesn't do anything other than that.