Example #1
0
/* Test non-NaN-resulting library calls. */
int test_defined(void) {
  int errs = 0;
  /*
   * Attempt to prevent constant folding and optimization of library
   * function bodies (when statically linked).
   */
  volatile double x;
  volatile double y;
  volatile double z;

  printf("Checking lib calls that take NaN, etc, but return non-NaN.\n");
  x = 0.0; y = 1.0;
  errs += CHECK_EQ_DOUBLE(pow(x, x), y);
  z = NAN;
  errs += CHECK_EQ_DOUBLE(pow(z, x), y);
  z = INFINITY;
  errs += CHECK_EQ_DOUBLE(pow(z, x), y);

  errs += CHECK_INF(sqrt(z));
  x = -0.0;
  errs += CHECK_EQ_DOUBLE(sqrt(x), x);
  x = INFINITY; y = 2.0;
  errs += CHECK_INF(pow(x, y));
  x = 0.0; y = -INFINITY;
  errs += ASSERT_TRUE(log(x) == y);

  return errs;
}
/* Test non-NaN-resulting library calls. */
int test_defined() {
  int errs = 0;

  printf("Checking lib calls that take NaN, etc, but return non-NaN.\n");
  errs += CHECK_EQ_DOUBLE(pow(0.0, 0.0), 1.0);
  errs += CHECK_EQ_DOUBLE(pow(NAN, 0.0), 1.0);
  errs += CHECK_EQ_DOUBLE(pow(INFINITY, 0.0), 1.0);

  errs += CHECK_INF(sqrt(INFINITY));
  errs += CHECK_EQ_DOUBLE(sqrt(-0.0), -0.0);
  errs += CHECK_INF(pow(INFINITY, 2.0));
  errs += ASSERT_TRUE(log(0) == -INFINITY);

  return errs;
}