java-semantics icon indicating copy to clipboard operation
java-semantics copied to clipboard

casting a floating-point number to an integer

Open rschumi0 opened this issue 5 years ago • 0 comments

There seems to be an issue when a cast is performed from a floating-point number that is larger than the maximum Integer to an Integer. In this case, the value should just be the largest Integer as documented in Section 5.1.3 of the JLS. However, K-Java performs this cast in the same way as a long to int cast as illustrated by the following example.

System.out.println(((int)2147483648L));
System.out.println(((int)2147483648.0)); // should be 2147483647

The same issue also occurs for a cast to other data types when floating-point numbers are involved.

rschumi0 avatar Jun 01 '20 23:06 rschumi0