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

wrong modulo computation for negative doubles or floats

Open rschumi0 opened this issue 4 years ago • 0 comments

There seems to be an issue with the modulo operator. The computation is wrong for all negative doubles and floats, i.e. it produces inconsistent values compared to Java and also compared to the same computation with Integer values. This is illustrated in the following examples.

System.out.println("-8 % 3 = "+(-8 % 3)); //both kjava and java return -2
System.out.println("-8.0 % 3.0 = "+(-8.0 % 3)); //kjava: 1.0 java: -2.0
System.out.println("8 % -3 = "+(8 % -3 )); // both return 2
System.out.println("8.0 % -3.0 = "+(8.0 % -3.0)); //kjava: -4.0 java: 2.0

rschumi0 avatar Feb 29 '20 23:02 rschumi0