On Tue, 22 Nov 2022 22:21:11 GMT, Kevin Rushforth <k...@openjdk.org> wrote:

>> good catch - I think the change is not equivalent.  It should be either
>> 
>> 4L * physicalWidth * physicalHeight;
>> 
>> 
>> or
>> 
>> 
>> ((long)physicalWidth) * physicalHeight * 4L;
>> 
>> 
>> the proposed change might result in overflow bc the first intermediate 
>> result is likely to be int.
>
> Actually, I think the new code correct, though less clear, since `(long)` is 
> applied to `physicalWidth` before the multiplication. The fact that we had to 
> scratch our head and discuss it highlights the point I was trying to make. I 
> do think this is one place where reverting the code back would be best. Then 
> it's obvious that all of the intermediate calculations are in long.

The cast has precedence and Java will not downcast mid calculation and lose 
precision, so all examples here are correct.

-------------

PR: https://git.openjdk.org/jfx/pull/960

Reply via email to