The Java Program: Rem.java

  1 // Rem.java -- remainder for real numbers too
  2 // IEEEremainder  f1 - f2*n  n is the closest integer
  3 // %              f1 - f2*n  n is the smallest integer
  4 
  5 class Rem {
  6    public static void main (String [] args) {
  7 
  8       System.out.println (23.7%3.1);                       //  2.0
  9       System.out.println (Math.IEEEremainder (23.7,3.1));  // -1.1
 10 
 11       System.out.println (23.7%3.53);                      //  2.52
 12       System.out.println (Math.IEEEremainder (23.7,3.53)); // -1.01
 13 
 14       System.out.println (23.7%3.9);                       //  0.3
 15       System.out.println (Math.IEEEremainder (23.7,3.9));  //  0.3
 16    }
 17 }