Rob Prime wrote:Don't use "1.0 *" just to get a double. Although unlikely that may already cause rounding issues.
Hmm, I don't agree with this. Based on
JLS 4.2.3, any integer value with magnitude less than 2^53 has an
exact double representation. There is no rounding error here. That applies to any int, but not any long - some longs are outside this range.
However even for values outside that range, the IEEE 754 round-to-nearest rule guarantees that adding extra zeroes after the decimal point cannot change what double value you end up rounding to. So these are guaranteed to all have the same double value, even though that value isn't really an exact representation of the original long value:
It's true that using doubles can introduce roundoff error. But in a case like this where using a double is
necessary, I can't see anything wrong with achieving that by appending ".0" to the number you wish to make a double. It works exactly the same way as far as I can tell. Is there something I'm overlooking? Do you have a counterexample?