1 public class FloatArithTests {
   2 
   3     private static float test_neg(float a) {
   4         return -a;
   5     }
   6 
   7     private static float test_add(float a, float b) {
   8         return a + b;
   9     }
  10 
  11     private static float test_sub(float a, float b) {
  12         return a - b;
  13     }
  14 
  15     private static float test_mul(float a, float b) {
  16         return a * b;
  17     }
  18 
  19     private static float test_div(float a, float b) {
  20         return a / b;
  21     }
  22 
  23     private static float test_rem(float a, float b) {
  24         return a % b;
  25     }
  26 
  27     private static void assertThat(boolean assertion) {
  28         if (! assertion) {
  29             throw new AssertionError();
  30         }
  31     }
  32 
  33     public static void main(String[] args) {
  34         assertThat(test_neg(10F) == -10F);
  35         assertThat(test_add(3F, 2F) == 5F);
  36 
  37         assertThat(test_sub(40F, 13F) == 27F);
  38 
  39         assertThat(test_mul(5F, 200F) == 1000F);
  40 
  41         assertThat(test_div(30F, 3F) == 10F);
  42         assertThat(test_div(30, 0) == Float.POSITIVE_INFINITY);
  43 
  44         assertThat(test_rem(30F, 3F) == 0);
  45         assertThat(test_rem(29F, 3F) == 2F);
  46         assertThat(Float.isNaN(test_rem(30F, 0F)));
  47 
  48     }
  49 }