java-semantics
java-semantics copied to clipboard
wrong modulo computation for negative doubles or floats
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