Example #1
0
  private static int testUnityULPCases() {
    int failures = 0;
    for (float sign : new float[] {-1, 1}) {
      for (float v1 : new float[] {1 << 23, 1 << 24}) {
        for (int k = -5; k <= 5; k++) {
          float value = (v1 + k) * sign;
          float actual = Math.round(value);
          failures += Tests.test("Math.round", value, actual, value);
        }
      }
    }

    if (failures != 0) {
      System.out.println();
    }

    for (double sign : new double[] {-1, 1}) {
      for (double v1 : new double[] {1L << 52, 1L << 53}) {
        for (int k = -5; k <= 5; k++) {
          double value = (v1 + k) * sign;
          double actual = Math.round(value);
          failures += Tests.test("Math.round", value, actual, value);
        }
      }
    }

    return failures;
  }
Example #2
0
  private static int testNearHalfCases(float input, float expected) {
    int failures = 0;

    failures += Tests.test("Math.round", input, Math.round(input), expected);
    failures += Tests.test("StrictMath.round", input, StrictMath.round(input), expected);

    return failures;
  }
Example #3
0
  private static int testSpecialCases() {
    int failures = 0;

    failures += Tests.test("Math.round", Float.NaN, Math.round(Float.NaN), 0.0F);
    failures +=
        Tests.test(
            "Math.round",
            Float.POSITIVE_INFINITY,
            Math.round(Float.POSITIVE_INFINITY),
            Integer.MAX_VALUE);
    failures +=
        Tests.test(
            "Math.round",
            Float.NEGATIVE_INFINITY,
            Math.round(Float.NEGATIVE_INFINITY),
            Integer.MIN_VALUE);
    failures +=
        Tests.test(
            "Math.round",
            -(float) Integer.MIN_VALUE,
            Math.round(-(float) Integer.MIN_VALUE),
            Integer.MAX_VALUE);
    failures +=
        Tests.test(
            "Math.round",
            (float) Integer.MIN_VALUE,
            Math.round((float) Integer.MIN_VALUE),
            Integer.MIN_VALUE);
    failures += Tests.test("Math.round", 0F, Math.round(0F), 0.0F);
    failures += Tests.test("Math.round", Float.MIN_VALUE, Math.round(Float.MIN_VALUE), 0.0F);
    failures += Tests.test("Math.round", -Float.MIN_VALUE, Math.round(-Float.MIN_VALUE), 0.0F);

    failures += Tests.test("Math.round", Double.NaN, Math.round(Double.NaN), 0.0);
    failures +=
        Tests.test(
            "Math.round",
            Double.POSITIVE_INFINITY,
            Math.round(Double.POSITIVE_INFINITY),
            Long.MAX_VALUE);
    failures +=
        Tests.test(
            "Math.round",
            Double.NEGATIVE_INFINITY,
            Math.round(Double.NEGATIVE_INFINITY),
            Long.MIN_VALUE);
    failures +=
        Tests.test(
            "Math.round",
            -(double) Long.MIN_VALUE,
            Math.round(-(double) Long.MIN_VALUE),
            Long.MAX_VALUE);
    failures +=
        Tests.test(
            "Math.round",
            (double) Long.MIN_VALUE,
            Math.round((double) Long.MIN_VALUE),
            Long.MIN_VALUE);
    failures += Tests.test("Math.round", 0, Math.round(0), 0.0);
    failures += Tests.test("Math.round", Double.MIN_VALUE, Math.round(Double.MIN_VALUE), 0.0);
    failures += Tests.test("Math.round", -Double.MIN_VALUE, Math.round(-Double.MIN_VALUE), 0.0);

    return failures;
  }