Exemplo n.º 1
0
void test_isunordered()
{
    static_assert((std::is_same<decltype(isunordered((float)0, (float)0)), bool>::value), "");
    static_assert((std::is_same<decltype(isunordered((float)0, (double)0)), bool>::value), "");
    static_assert((std::is_same<decltype(isunordered((float)0, (long double)0)), bool>::value), "");
    static_assert((std::is_same<decltype(isunordered((double)0, (float)0)), bool>::value), "");
    static_assert((std::is_same<decltype(isunordered((double)0, (double)0)), bool>::value), "");
    static_assert((std::is_same<decltype(isunordered((double)0, (long double)0)), bool>::value), "");
    static_assert((std::is_same<decltype(isunordered((long double)0, (float)0)), bool>::value), "");
    static_assert((std::is_same<decltype(isunordered((long double)0, (double)0)), bool>::value), "");
    static_assert((std::is_same<decltype(isunordered((long double)0, (long double)0)), bool>::value), "");
    assert(isunordered(-1.0, 0.F) == false);
}
Exemplo n.º 2
0
int test_compares(void) {
  int errs = 0;
  /* Attempt to prevent constant folding */
  volatile double x;
  volatile double y;

  printf("Comparing float constants\n");
  x = NAN;
  errs += ASSERT_TRUE(x != x);
  errs += ASSERT_TRUE(isunordered(x, x));
  errs += CHECK_NAN(x + 3.0f);
  errs += CHECK_NAN(x + x);
  errs += CHECK_NAN(x - x);
  errs += CHECK_NAN(x / x);
  errs += CHECK_NAN(0.0 / x);
  errs += CHECK_NAN(0.0 * x);

  errs += ASSERT_FALSE(x == x);

  x = INFINITY;
  errs += ASSERT_TRUE(x == x);
  errs += ASSERT_FALSE(x == -x);
  errs += ASSERT_TRUE(-x == -x);
  errs += ASSERT_TRUE(x + 100.0 == x);
  errs += ASSERT_TRUE(x - 100.0 == x);
  errs += ASSERT_TRUE(-x - 100.0 == -x);
  errs += ASSERT_TRUE(-x + 100.0 == -x);
  errs += ASSERT_TRUE(-x < x);
  errs += ASSERT_FALSE(-x > x);

  y = 0.0;
  errs += CHECK_NAN(y * x);
  errs += CHECK_NAN(y / y);
  errs += CHECK_NAN(x / x);
  errs += CHECK_NAN(x - x);
  y = NAN;
  errs += CHECK_NAN(x * y);

  x = INFINITY;
  errs += CHECK_INF(x + x);
  x = 1.0; y = 0.0;
  errs += CHECK_INF(x / y);

  x = INFINITY;
  errs += ASSERT_FALSE(isfinite(x));
  x = NAN;
  errs += ASSERT_FALSE(isfinite(x));

  return errs;
}
Exemplo n.º 3
0
float
__nexttowardf(float x, long double y) {
	union {
		unsigned i;
		float f;
	} xx;
	unsigned hx;
	long double lx;
	volatile float dummy;

	lx = xx.f = x;
	hx = xx.i & ~0x80000000;

	/* check for each of four possible orderings */
	if (isunordered(lx, y))
		return ((float) (lx + y));

	if (lx == y)
		return ((float) y);

	if (lx < y) {
		if (hx == 0)	/* x is zero */
			xx.i = 0x00000001;
		else if ((int) xx.i >= 0)	/* x is positive */
			xx.i++;
		else
			xx.i--;
	} else {
		if (hx == 0)	/* x is zero */
			xx.i = 0x80000001;
		else if ((int) xx.i >= 0)	/* x is positive */
			xx.i--;
		else
			xx.i++;
	}

	/* raise exceptions as needed */
	hx = xx.i & ~0x80000000;
	if (hx == 0x7f800000) {
		dummy = huge;
		dummy *= huge;
	} else if (hx < 0x00800000) {
		dummy = tiny;
		dummy *= tiny;
	}

	return (xx.f);
}
Exemplo n.º 4
0
int test_compares() {
  int errs = 0;

  printf("Comparing float constants\n");
  errs += ASSERT_TRUE(NAN != NAN);
  errs += ASSERT_TRUE(isunordered(NAN, NAN));
  errs += CHECK_NAN(NAN + 3.0f);
  errs += CHECK_NAN(NAN + NAN);
  errs += CHECK_NAN(NAN - NAN);
  errs += CHECK_NAN(NAN / NAN);
  errs += CHECK_NAN(0.0 / NAN);
  errs += CHECK_NAN(0.0 * NAN);

  errs += ASSERT_FALSE(NAN == NAN);

  errs += ASSERT_TRUE(INFINITY == INFINITY);
  errs += ASSERT_FALSE(INFINITY == -INFINITY);
  errs += ASSERT_TRUE(-INFINITY == -INFINITY);
  errs += ASSERT_TRUE(INFINITY + 100.0 == INFINITY);
  errs += ASSERT_TRUE(INFINITY - 100.0 == INFINITY);
  errs += ASSERT_TRUE(-INFINITY - 100.0 == -INFINITY);
  errs += ASSERT_TRUE(-INFINITY + 100.0 == -INFINITY);
  errs += ASSERT_TRUE(-INFINITY < INFINITY);
  errs += ASSERT_FALSE(-INFINITY > INFINITY);

  errs += CHECK_NAN(0.0 * INFINITY);
  errs += CHECK_NAN(0.0 / 0.0);
  errs += CHECK_NAN(INFINITY / INFINITY);
  errs += CHECK_NAN(INFINITY - INFINITY);
  errs += CHECK_NAN(INFINITY * NAN);

  errs += CHECK_INF(INFINITY + INFINITY);
  errs += CHECK_INF(1.0 / 0.0);

  errs += ASSERT_FALSE(isfinite(INFINITY));
  errs += ASSERT_FALSE(isfinite(NAN));

  return errs;
}
static void
avx_test ()
{
    __m256d source1, source2, dest;
    int i;

    CMP(_CMP_EQ_OQ, !isunordered(s1[i], s2[i]) && s1[i] == s2[i]);
    CMP(_CMP_LT_OS, !isunordered(s1[i], s2[i]) && s1[i] < s2[i]);
    CMP(_CMP_LE_OS, !isunordered(s1[i], s2[i]) && s1[i] <= s2[i]);
    CMP(_CMP_UNORD_Q, isunordered(s1[i], s2[i]));
    CMP(_CMP_NEQ_UQ, isunordered(s1[i], s2[i]) || s1[i] != s2[i]);
    CMP(_CMP_NLT_US, isunordered(s1[i], s2[i]) || s1[i] >= s2[i]);
    CMP(_CMP_NLE_US, isunordered(s1[i], s2[i]) || s1[i] > s2[i]);
    CMP(_CMP_ORD_Q, !isunordered(s1[i], s2[i]));

    CMP(_CMP_EQ_UQ, isunordered(s1[i], s2[i]) || s1[i] == s2[i]);
    CMP(_CMP_NGE_US, isunordered(s1[i], s2[i]) || s1[i] < s2[i]);
    CMP(_CMP_NGT_US, isunordered(s1[i], s2[i]) || s1[i] <= s2[i]);

    CMP(_CMP_FALSE_OQ, 0);
    CMP(_CMP_NEQ_OQ, !isunordered(s1[i], s2[i]) && s1[i] != s2[i]);
    CMP(_CMP_GE_OS, !isunordered(s1[i], s2[i]) && s1[i] >= s2[i]);
    CMP(_CMP_GT_OS, !isunordered(s1[i], s2[i]) && s1[i] > s2[i]);
    CMP(_CMP_TRUE_UQ, 1);

    CMP(_CMP_EQ_OS, !isunordered(s1[i], s2[i]) && s1[i] == s2[i]);
    CMP(_CMP_LT_OQ, !isunordered(s1[i], s2[i]) && s1[i] < s2[i]);
    CMP(_CMP_LE_OQ, !isunordered(s1[i], s2[i]) && s1[i] <= s2[i]);
    CMP(_CMP_UNORD_S, isunordered(s1[i], s2[i]));
    CMP(_CMP_NEQ_US, isunordered(s1[i], s2[i]) || s1[i] != s2[i]);
    CMP(_CMP_NLT_UQ, isunordered(s1[i], s2[i]) || s1[i] >= s2[i]);
    CMP(_CMP_NLE_UQ, isunordered(s1[i], s2[i]) || s1[i] > s2[i]);
    CMP(_CMP_ORD_S, !isunordered(s1[i], s2[i]));
    CMP(_CMP_EQ_US, isunordered(s1[i], s2[i]) || s1[i] == s2[i]);
    CMP(_CMP_NGE_UQ, isunordered(s1[i], s2[i]) || s1[i] < s2[i]);
    CMP(_CMP_NGT_UQ, isunordered(s1[i], s2[i]) || s1[i] <= s2[i]);
    CMP(_CMP_FALSE_OS, 0);
    CMP(_CMP_NEQ_OS, !isunordered(s1[i], s2[i]) && s1[i] != s2[i]);
    CMP(_CMP_GE_OQ, !isunordered(s1[i], s2[i]) && s1[i] >= s2[i]);
    CMP(_CMP_GT_OQ, !isunordered(s1[i], s2[i]) && s1[i] > s2[i]);
    CMP(_CMP_TRUE_US, 1);

}
Exemplo n.º 6
0
TEST ()
{
    UNION_TYPE (AVX512F_LEN,) source1, source2;
    MASK_TYPE dst1, dst2, dst_ref;
    MASK_TYPE mask = MASK_VALUE;
    int i;
    float s1[16] = {2134.3343, 6678.346, 453.345635, 54646.464,
		    231.23311, 5674.455, 111.111111, 23241.152,
		    123.14811, 1245.124, 244.151353, 53454.141,
		    926.16717, 3733.261, 643.161644, 23514.633};
    float s2[16] = {41124.234, 6678.346, 8653.65635, 856.43576,
		    231.23311, 4646.123, 111.111111, 124.12455,
		    123.14811, 1245.124, 244.151353, 53454.141,
		    2134.3343, 6678.346, 453.345635, 54646.464};

    CMP(_CMP_EQ_OQ, !isunordered(s1[i], s2[i]) && s1[i] == s2[i]);
    CMP(_CMP_LT_OS, !isunordered(s1[i], s2[i]) && s1[i] < s2[i]);
    CMP(_CMP_LE_OS, !isunordered(s1[i], s2[i]) && s1[i] <= s2[i]);
    CMP(_CMP_UNORD_Q, isunordered(s1[i], s2[i]));
    CMP(_CMP_NEQ_UQ, isunordered(s1[i], s2[i]) || s1[i] != s2[i]);
    CMP(_CMP_NLT_US, isunordered(s1[i], s2[i]) || s1[i] >= s2[i]);
    CMP(_CMP_NLE_US, isunordered(s1[i], s2[i]) || s1[i] > s2[i]);
    CMP(_CMP_ORD_Q, !isunordered(s1[i], s2[i]));

    CMP(_CMP_EQ_UQ, isunordered(s1[i], s2[i]) || s1[i] == s2[i]);
    CMP(_CMP_NGE_US, isunordered(s1[i], s2[i]) || s1[i] < s2[i]);
    CMP(_CMP_NGT_US, isunordered(s1[i], s2[i]) || s1[i] <= s2[i]);

    CMP(_CMP_FALSE_OQ, 0);
    CMP(_CMP_NEQ_OQ, !isunordered(s1[i], s2[i]) && s1[i] != s2[i]);
    CMP(_CMP_GE_OS, !isunordered(s1[i], s2[i]) && s1[i] >= s2[i]);
Exemplo n.º 7
0
void
domathl (void)
{
#ifndef NO_LONG_DOUBLE
  long double f1;
  long double f2;

  int i1;

  f1 = acosl(0.0);
  fprintf( stdout, "acosl          : %Lf\n", f1);

  f1 = acoshl(0.0);
  fprintf( stdout, "acoshl         : %Lf\n", f1);

  f1 = asinl(1.0);
  fprintf( stdout, "asinl          : %Lf\n", f1);

  f1 = asinhl(1.0);
  fprintf( stdout, "asinhl         : %Lf\n", f1);

  f1 = atanl(M_PI_4);
  fprintf( stdout, "atanl          : %Lf\n", f1);

  f1 = atan2l(2.3, 2.3);
  fprintf( stdout, "atan2l         : %Lf\n", f1);

  f1 = atanhl(1.0);
  fprintf( stdout, "atanhl         : %Lf\n", f1);

  f1 = cbrtl(27.0);
  fprintf( stdout, "cbrtl          : %Lf\n", f1);

  f1 = ceill(3.5);
  fprintf( stdout, "ceill          : %Lf\n", f1);

  f1 = copysignl(3.5, -2.5);
  fprintf( stdout, "copysignl      : %Lf\n", f1);

  f1 = cosl(M_PI_2);
  fprintf( stdout, "cosl           : %Lf\n", f1);

  f1 = coshl(M_PI_2);
  fprintf( stdout, "coshl          : %Lf\n", f1);

  f1 = erfl(42.0);
  fprintf( stdout, "erfl           : %Lf\n", f1);

  f1 = erfcl(42.0);
  fprintf( stdout, "erfcl          : %Lf\n", f1);

  f1 = expl(0.42);
  fprintf( stdout, "expl           : %Lf\n", f1);

  f1 = exp2l(0.42);
  fprintf( stdout, "exp2l          : %Lf\n", f1);

  f1 = expm1l(0.00042);
  fprintf( stdout, "expm1l         : %Lf\n", f1);

  f1 = fabsl(-1.123);
  fprintf( stdout, "fabsl          : %Lf\n", f1);

  f1 = fdiml(1.123, 2.123);
  fprintf( stdout, "fdiml          : %Lf\n", f1);

  f1 = floorl(0.5);
  fprintf( stdout, "floorl         : %Lf\n", f1);
  f1 = floorl(-0.5);
  fprintf( stdout, "floorl         : %Lf\n", f1);

  f1 = fmal(2.1, 2.2, 3.01);
  fprintf( stdout, "fmal           : %Lf\n", f1);

  f1 = fmaxl(-0.42, 0.42);
  fprintf( stdout, "fmaxl          : %Lf\n", f1);

  f1 = fminl(-0.42, 0.42);
  fprintf( stdout, "fminl          : %Lf\n", f1);

  f1 = fmodl(42.0, 3.0);
  fprintf( stdout, "fmodl          : %Lf\n", f1);

  /* no type-specific variant */
  i1 = fpclassify(1.0);
  fprintf( stdout, "fpclassify     : %d\n", i1);

  f1 = frexpl(42.0, &i1);
  fprintf( stdout, "frexpl         : %Lf\n", f1);

  f1 = hypotl(42.0, 42.0);
  fprintf( stdout, "hypotl         : %Lf\n", f1);

  i1 = ilogbl(42.0);
  fprintf( stdout, "ilogbl         : %d\n", i1);

  /* no type-specific variant */
  i1 = isfinite(3.0);
  fprintf( stdout, "isfinite       : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreater(3.0, 3.1);
  fprintf( stdout, "isgreater      : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreaterequal(3.0, 3.1);
  fprintf( stdout, "isgreaterequal : %d\n", i1);

  /* no type-specific variant */
  i1 = isinf(3.0);
  fprintf( stdout, "isinf          : %d\n", i1);

  /* no type-specific variant */
  i1 = isless(3.0, 3.1);
  fprintf( stdout, "isless         : %d\n", i1);

  /* no type-specific variant */
  i1 = islessequal(3.0, 3.1);
  fprintf( stdout, "islessequal    : %d\n", i1);

  /* no type-specific variant */
  i1 = islessgreater(3.0, 3.1);
  fprintf( stdout, "islessgreater  : %d\n", i1);

  /* no type-specific variant */
  i1 = isnan(0.0);
  fprintf( stdout, "isnan          : %d\n", i1);

  /* no type-specific variant */
  i1 = isnormal(3.0);
  fprintf( stdout, "isnormal       : %d\n", i1);

  /* no type-specific variant */
  f1 = isunordered(1.0, 2.0);
  fprintf( stdout, "isunordered    : %d\n", i1);

  f1 = j0l(1.2);
  fprintf( stdout, "j0l            : %Lf\n", f1);

  f1 = j1l(1.2);
  fprintf( stdout, "j1l            : %Lf\n", f1);

  f1 = jnl(2,1.2);
  fprintf( stdout, "jnl            : %Lf\n", f1);

  f1 = ldexpl(1.2,3);
  fprintf( stdout, "ldexpl         : %Lf\n", f1);

  f1 = lgammal(42.0);
  fprintf( stdout, "lgammal        : %Lf\n", f1);

  f1 = llrintl(-0.5);
  fprintf( stdout, "llrintl        : %Lf\n", f1);
  f1 = llrintl(0.5);
  fprintf( stdout, "llrintl        : %Lf\n", f1);

  f1 = llroundl(-0.5);
  fprintf( stdout, "lroundl        : %Lf\n", f1);
  f1 = llroundl(0.5);
  fprintf( stdout, "lroundl        : %Lf\n", f1);

  f1 = logl(42.0);
  fprintf( stdout, "logl           : %Lf\n", f1);

  f1 = log10l(42.0);
  fprintf( stdout, "log10l         : %Lf\n", f1);

  f1 = log1pl(42.0);
  fprintf( stdout, "log1pl         : %Lf\n", f1);

  f1 = log2l(42.0);
  fprintf( stdout, "log2l          : %Lf\n", f1);

  f1 = logbl(42.0);
  fprintf( stdout, "logbl          : %Lf\n", f1);

  f1 = lrintl(-0.5);
  fprintf( stdout, "lrintl         : %Lf\n", f1);
  f1 = lrintl(0.5);
  fprintf( stdout, "lrintl         : %Lf\n", f1);

  f1 = lroundl(-0.5);
  fprintf( stdout, "lroundl        : %Lf\n", f1);
  f1 = lroundl(0.5);
  fprintf( stdout, "lroundl        : %Lf\n", f1);

  f1 = modfl(42.0,&f2);
  fprintf( stdout, "lmodfl         : %Lf\n", f1);

  f1 = nanl("");
  fprintf( stdout, "nanl           : %Lf\n", f1);

  f1 = nearbyintl(1.5);
  fprintf( stdout, "nearbyintl     : %Lf\n", f1);

  f1 = nextafterl(1.5,2.0);
  fprintf( stdout, "nextafterl     : %Lf\n", f1);

  f1 = powl(3.01, 2.0);
  fprintf( stdout, "powl           : %Lf\n", f1);

  f1 = remainderl(3.01,2.0);
  fprintf( stdout, "remainderl     : %Lf\n", f1);

  f1 = remquol(29.0,3.0,&i1);
  fprintf( stdout, "remquol        : %Lf\n", f1);

  f1 = rintl(0.5);
  fprintf( stdout, "rintl          : %Lf\n", f1);
  f1 = rintl(-0.5);
  fprintf( stdout, "rintl          : %Lf\n", f1);

  f1 = roundl(0.5);
  fprintf( stdout, "roundl         : %Lf\n", f1);
  f1 = roundl(-0.5);
  fprintf( stdout, "roundl         : %Lf\n", f1);

  f1 = scalblnl(1.2,3);
  fprintf( stdout, "scalblnl       : %Lf\n", f1);

  f1 = scalbnl(1.2,3);
  fprintf( stdout, "scalbnl        : %Lf\n", f1);

  /* no type-specific variant */
  i1 = signbit(1.0);
  fprintf( stdout, "signbit        : %i\n", i1);

  f1 = sinl(M_PI_4);
  fprintf( stdout, "sinl           : %Lf\n", f1);

  f1 = sinhl(M_PI_4);
  fprintf( stdout, "sinhl          : %Lf\n", f1);

  f1 = sqrtl(9.0);
  fprintf( stdout, "sqrtl          : %Lf\n", f1);

  f1 = tanl(M_PI_4);
  fprintf( stdout, "tanl           : %Lf\n", f1);

  f1 = tanhl(M_PI_4);
  fprintf( stdout, "tanhl          : %Lf\n", f1);

  f1 = tgammal(2.1);
  fprintf( stdout, "tgammal        : %Lf\n", f1);

  f1 = truncl(3.5);
  fprintf( stdout, "truncl         : %Lf\n", f1);

  f1 = y0l(1.2);
  fprintf( stdout, "y0l            : %Lf\n", f1);

  f1 = y1l(1.2);
  fprintf( stdout, "y1l            : %Lf\n", f1);

  f1 = ynl(3,1.2);
  fprintf( stdout, "ynl            : %Lf\n", f1);
#endif
}
Exemplo n.º 8
0
void
domathf (void)
{
#ifndef NO_FLOAT
  float f1;
  float f2;

  int i1;

  f1 = acosf(0.0);
  fprintf( stdout, "acosf          : %f\n", f1);

  f1 = acoshf(0.0);
  fprintf( stdout, "acoshf         : %f\n", f1);

  f1 = asinf(1.0);
  fprintf( stdout, "asinf          : %f\n", f1);

  f1 = asinhf(1.0);
  fprintf( stdout, "asinhf         : %f\n", f1);

  f1 = atanf(M_PI_4);
  fprintf( stdout, "atanf          : %f\n", f1);

  f1 = atan2f(2.3, 2.3);
  fprintf( stdout, "atan2f         : %f\n", f1);

  f1 = atanhf(1.0);
  fprintf( stdout, "atanhf         : %f\n", f1);

  f1 = cbrtf(27.0);
  fprintf( stdout, "cbrtf          : %f\n", f1);

  f1 = ceilf(3.5);
  fprintf( stdout, "ceilf          : %f\n", f1);

  f1 = copysignf(3.5, -2.5);
  fprintf( stdout, "copysignf      : %f\n", f1);

  f1 = cosf(M_PI_2);
  fprintf( stdout, "cosf           : %f\n", f1);

  f1 = coshf(M_PI_2);
  fprintf( stdout, "coshf          : %f\n", f1);

  f1 = erff(42.0);
  fprintf( stdout, "erff           : %f\n", f1);

  f1 = erfcf(42.0);
  fprintf( stdout, "erfcf          : %f\n", f1);

  f1 = expf(0.42);
  fprintf( stdout, "expf           : %f\n", f1);

  f1 = exp2f(0.42);
  fprintf( stdout, "exp2f          : %f\n", f1);

  f1 = expm1f(0.00042);
  fprintf( stdout, "expm1f         : %f\n", f1);

  f1 = fabsf(-1.123);
  fprintf( stdout, "fabsf          : %f\n", f1);

  f1 = fdimf(1.123, 2.123);
  fprintf( stdout, "fdimf          : %f\n", f1);

  f1 = floorf(0.5);
  fprintf( stdout, "floorf         : %f\n", f1);
  f1 = floorf(-0.5);
  fprintf( stdout, "floorf         : %f\n", f1);

  f1 = fmaf(2.1, 2.2, 3.01);
  fprintf( stdout, "fmaf           : %f\n", f1);

  f1 = fmaxf(-0.42, 0.42);
  fprintf( stdout, "fmaxf          : %f\n", f1);

  f1 = fminf(-0.42, 0.42);
  fprintf( stdout, "fminf          : %f\n", f1);

  f1 = fmodf(42.0, 3.0);
  fprintf( stdout, "fmodf          : %f\n", f1);

  /* no type-specific variant */
  i1 = fpclassify(1.0);
  fprintf( stdout, "fpclassify     : %d\n", i1);

  f1 = frexpf(42.0, &i1);
  fprintf( stdout, "frexpf         : %f\n", f1);

  f1 = hypotf(42.0, 42.0);
  fprintf( stdout, "hypotf         : %f\n", f1);

  i1 = ilogbf(42.0);
  fprintf( stdout, "ilogbf         : %d\n", i1);

  /* no type-specific variant */
  i1 = isfinite(3.0);
  fprintf( stdout, "isfinite       : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreater(3.0, 3.1);
  fprintf( stdout, "isgreater      : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreaterequal(3.0, 3.1);
  fprintf( stdout, "isgreaterequal : %d\n", i1);

  /* no type-specific variant */
  i1 = isinf(3.0);
  fprintf( stdout, "isinf          : %d\n", i1);

  /* no type-specific variant */
  i1 = isless(3.0, 3.1);
  fprintf( stdout, "isless         : %d\n", i1);

  /* no type-specific variant */
  i1 = islessequal(3.0, 3.1);
  fprintf( stdout, "islessequal    : %d\n", i1);

  /* no type-specific variant */
  i1 = islessgreater(3.0, 3.1);
  fprintf( stdout, "islessgreater  : %d\n", i1);

  /* no type-specific variant */
  i1 = isnan(0.0);
  fprintf( stdout, "isnan          : %d\n", i1);

  /* no type-specific variant */
  i1 = isnormal(3.0);
  fprintf( stdout, "isnormal       : %d\n", i1);

  /* no type-specific variant */
  f1 = isunordered(1.0, 2.0);
  fprintf( stdout, "isunordered    : %d\n", i1);

  f1 = j0f(1.2);
  fprintf( stdout, "j0f            : %f\n", f1);

  f1 = j1f(1.2);
  fprintf( stdout, "j1f            : %f\n", f1);

  f1 = jnf(2,1.2);
  fprintf( stdout, "jnf            : %f\n", f1);

  f1 = ldexpf(1.2,3);
  fprintf( stdout, "ldexpf         : %f\n", f1);

  f1 = lgammaf(42.0);
  fprintf( stdout, "lgammaf        : %f\n", f1);

  f1 = llrintf(-0.5);
  fprintf( stdout, "llrintf        : %f\n", f1);
  f1 = llrintf(0.5);
  fprintf( stdout, "llrintf        : %f\n", f1);

  f1 = llroundf(-0.5);
  fprintf( stdout, "lroundf        : %f\n", f1);
  f1 = llroundf(0.5);
  fprintf( stdout, "lroundf        : %f\n", f1);

  f1 = logf(42.0);
  fprintf( stdout, "logf           : %f\n", f1);

  f1 = log10f(42.0);
  fprintf( stdout, "log10f         : %f\n", f1);

  f1 = log1pf(42.0);
  fprintf( stdout, "log1pf         : %f\n", f1);

  f1 = log2f(42.0);
  fprintf( stdout, "log2f          : %f\n", f1);

  f1 = logbf(42.0);
  fprintf( stdout, "logbf          : %f\n", f1);

  f1 = lrintf(-0.5);
  fprintf( stdout, "lrintf         : %f\n", f1);
  f1 = lrintf(0.5);
  fprintf( stdout, "lrintf         : %f\n", f1);

  f1 = lroundf(-0.5);
  fprintf( stdout, "lroundf        : %f\n", f1);
  f1 = lroundf(0.5);
  fprintf( stdout, "lroundf        : %f\n", f1);

  f1 = modff(42.0,&f2);
  fprintf( stdout, "lmodff         : %f\n", f1);

  f1 = nanf("");
  fprintf( stdout, "nanf           : %f\n", f1);

  f1 = nearbyintf(1.5);
  fprintf( stdout, "nearbyintf     : %f\n", f1);

  f1 = nextafterf(1.5,2.0);
  fprintf( stdout, "nextafterf     : %f\n", f1);

  f1 = powf(3.01, 2.0);
  fprintf( stdout, "powf           : %f\n", f1);

  f1 = remainderf(3.01,2.0);
  fprintf( stdout, "remainderf     : %f\n", f1);

  f1 = remquof(29.0,3.0,&i1);
  fprintf( stdout, "remquof        : %f\n", f1);

  f1 = rintf(0.5);
  fprintf( stdout, "rintf          : %f\n", f1);
  f1 = rintf(-0.5);
  fprintf( stdout, "rintf          : %f\n", f1);

  f1 = roundf(0.5);
  fprintf( stdout, "roundf         : %f\n", f1);
  f1 = roundf(-0.5);
  fprintf( stdout, "roundf         : %f\n", f1);

  f1 = scalblnf(1.2,3);
  fprintf( stdout, "scalblnf       : %f\n", f1);

  f1 = scalbnf(1.2,3);
  fprintf( stdout, "scalbnf        : %f\n", f1);

  /* no type-specific variant */
  i1 = signbit(1.0);
  fprintf( stdout, "signbit        : %i\n", i1);

  f1 = sinf(M_PI_4);
  fprintf( stdout, "sinf           : %f\n", f1);

  f1 = sinhf(M_PI_4);
  fprintf( stdout, "sinhf          : %f\n", f1);

  f1 = sqrtf(9.0);
  fprintf( stdout, "sqrtf          : %f\n", f1);

  f1 = tanf(M_PI_4);
  fprintf( stdout, "tanf           : %f\n", f1);

  f1 = tanhf(M_PI_4);
  fprintf( stdout, "tanhf          : %f\n", f1);

  f1 = tgammaf(2.1);
  fprintf( stdout, "tgammaf        : %f\n", f1);

  f1 = truncf(3.5);
  fprintf( stdout, "truncf         : %f\n", f1);

  f1 = y0f(1.2);
  fprintf( stdout, "y0f            : %f\n", f1);

  f1 = y1f(1.2);
  fprintf( stdout, "y1f            : %f\n", f1);

  f1 = ynf(3,1.2);
  fprintf( stdout, "ynf            : %f\n", f1);
#endif
}
static void
avx_test ()
{
    __m128 source1, source2, dest;
    int i;

#define CMP(imm, rel)					\
    for (i = 0; i < 4; i++) e[i] = rel ? -1 : 0;	\
    source1 = _mm_loadu_ps(s1);				\
    source2 = _mm_loadu_ps(s2);				\
    dest = _mm_cmp_ps(source1, source2, imm);		\
    _mm_storeu_ps(d.f, dest);			\
    check(imm, "" #imm "");

    CMP(_CMP_EQ_OQ, !isunordered(s1[i], s2[i]) && s1[i] == s2[i]);
    CMP(_CMP_LT_OS, !isunordered(s1[i], s2[i]) && s1[i] < s2[i]);
    CMP(_CMP_LE_OS, !isunordered(s1[i], s2[i]) && s1[i] <= s2[i]);
    CMP(_CMP_UNORD_Q, isunordered(s1[i], s2[i]));
    CMP(_CMP_NEQ_UQ, isunordered(s1[i], s2[i]) || s1[i] != s2[i]);
    CMP(_CMP_NLT_US, isunordered(s1[i], s2[i]) || s1[i] >= s2[i]);
    CMP(_CMP_NLE_US, isunordered(s1[i], s2[i]) || s1[i] > s2[i]);
    CMP(_CMP_ORD_Q, !isunordered(s1[i], s2[i]));

    CMP(_CMP_EQ_UQ, isunordered(s1[i], s2[i]) || s1[i] == s2[i]);
    CMP(_CMP_NGE_US, isunordered(s1[i], s2[i]) || s1[i] < s2[i]);
    CMP(_CMP_NGT_US, isunordered(s1[i], s2[i]) || s1[i] <= s2[i]);

    CMP(_CMP_FALSE_OQ, 0);
    CMP(_CMP_NEQ_OQ, !isunordered(s1[i], s2[i]) && s1[i] != s2[i]);
    CMP(_CMP_GE_OS, !isunordered(s1[i], s2[i]) && s1[i] >= s2[i]);
    CMP(_CMP_GT_OS, !isunordered(s1[i], s2[i]) && s1[i] > s2[i]);
    CMP(_CMP_TRUE_UQ, 1);

    CMP(_CMP_EQ_OS, !isunordered(s1[i], s2[i]) && s1[i] == s2[i]);
    CMP(_CMP_LT_OQ, !isunordered(s1[i], s2[i]) && s1[i] < s2[i]);
    CMP(_CMP_LE_OQ, !isunordered(s1[i], s2[i]) && s1[i] <= s2[i]);
    CMP(_CMP_UNORD_S, isunordered(s1[i], s2[i]));
    CMP(_CMP_NEQ_US, isunordered(s1[i], s2[i]) || s1[i] != s2[i]);
    CMP(_CMP_NLT_UQ, isunordered(s1[i], s2[i]) || s1[i] >= s2[i]);
    CMP(_CMP_NLE_UQ, isunordered(s1[i], s2[i]) || s1[i] > s2[i]);
    CMP(_CMP_ORD_S, !isunordered(s1[i], s2[i]));
    CMP(_CMP_EQ_US, isunordered(s1[i], s2[i]) || s1[i] == s2[i]);
    CMP(_CMP_NGE_UQ, isunordered(s1[i], s2[i]) || s1[i] < s2[i]);
    CMP(_CMP_NGT_UQ, isunordered(s1[i], s2[i]) || s1[i] <= s2[i]);
    CMP(_CMP_FALSE_OS, 0);
    CMP(_CMP_NEQ_OS, !isunordered(s1[i], s2[i]) && s1[i] != s2[i]);
    CMP(_CMP_GE_OQ, !isunordered(s1[i], s2[i]) && s1[i] >= s2[i]);
    CMP(_CMP_GT_OQ, !isunordered(s1[i], s2[i]) && s1[i] > s2[i]);
    CMP(_CMP_TRUE_US, 1);
}
Exemplo n.º 10
0
void
domath  (void)
{
#ifndef NO_DOUBLE
  double f1;
  double f2;

  int i1;

  f1 = acos (0.0);
  fprintf( stdout, "acos           : %f\n", f1);

  f1 = acosh (0.0);
  fprintf( stdout, "acosh          : %f\n", f1);

  f1 = asin (1.0);
  fprintf( stdout, "asin           : %f\n", f1);

  f1 = asinh (1.0);
  fprintf( stdout, "asinh          : %f\n", f1);

  f1 = atan (M_PI_4);
  fprintf( stdout, "atan           : %f\n", f1);

  f1 = atan2 (2.3, 2.3);
  fprintf( stdout, "atan2          : %f\n", f1);

  f1 = atanh (1.0);
  fprintf( stdout, "atanh          : %f\n", f1);

  f1 = cbrt (27.0);
  fprintf( stdout, "cbrt           : %f\n", f1);

  f1 = ceil (3.5);
  fprintf( stdout, "ceil           : %f\n", f1);

  f1 = copysign (3.5, -2.5);
  fprintf( stdout, "copysign       : %f\n", f1);

  f1 = cos (M_PI_2);
  fprintf( stdout, "cos            : %f\n", f1);

  f1 = cosh (M_PI_2);
  fprintf( stdout, "cosh           : %f\n", f1);

  f1 = erf (42.0);
  fprintf( stdout, "erf            : %f\n", f1);

  f1 = erfc (42.0);
  fprintf( stdout, "erfc           : %f\n", f1);

  f1 = exp (0.42);
  fprintf( stdout, "exp            : %f\n", f1);

  f1 = exp2 (0.42);
  fprintf( stdout, "exp2           : %f\n", f1);

  f1 = expm1 (0.00042);
  fprintf( stdout, "expm1          : %f\n", f1);

  f1 = fabs (-1.123);
  fprintf( stdout, "fabs           : %f\n", f1);

  f1 = fdim (1.123, 2.123);
  fprintf( stdout, "fdim           : %f\n", f1);

  f1 = floor (0.5);
  fprintf( stdout, "floor          : %f\n", f1);
  f1 = floor (-0.5);
  fprintf( stdout, "floor          : %f\n", f1);

  f1 = fma (2.1, 2.2, 3.01);
  fprintf( stdout, "fma            : %f\n", f1);

  f1 = fmax (-0.42, 0.42);
  fprintf( stdout, "fmax           : %f\n", f1);

  f1 = fmin (-0.42, 0.42);
  fprintf( stdout, "fmin           : %f\n", f1);

  f1 = fmod (42.0, 3.0);
  fprintf( stdout, "fmod           : %f\n", f1);

  /* no type-specific variant */
  i1 = fpclassify(1.0);
  fprintf( stdout, "fpclassify     : %d\n", i1);

  f1 = frexp (42.0, &i1);
  fprintf( stdout, "frexp          : %f\n", f1);

  f1 = hypot (42.0, 42.0);
  fprintf( stdout, "hypot          : %f\n", f1);

  i1 = ilogb (42.0);
  fprintf( stdout, "ilogb          : %d\n", i1);

  /* no type-specific variant */
  i1 = isfinite(3.0);
  fprintf( stdout, "isfinite       : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreater(3.0, 3.1);
  fprintf( stdout, "isgreater      : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreaterequal(3.0, 3.1);
  fprintf( stdout, "isgreaterequal : %d\n", i1);

  /* no type-specific variant */
  i1 = isinf(3.0);
  fprintf( stdout, "isinf          : %d\n", i1);

  /* no type-specific variant */
  i1 = isless(3.0, 3.1);
  fprintf( stdout, "isless         : %d\n", i1);

  /* no type-specific variant */
  i1 = islessequal(3.0, 3.1);
  fprintf( stdout, "islessequal    : %d\n", i1);

  /* no type-specific variant */
  i1 = islessgreater(3.0, 3.1);
  fprintf( stdout, "islessgreater  : %d\n", i1);

  /* no type-specific variant */
  i1 = isnan(0.0);
  fprintf( stdout, "isnan          : %d\n", i1);

  /* no type-specific variant */
  i1 = isnormal(3.0);
  fprintf( stdout, "isnormal       : %d\n", i1);

  /* no type-specific variant */
  f1 = isunordered(1.0, 2.0);
  fprintf( stdout, "isunordered    : %d\n", i1);

  f1 = j0 (1.2);
  fprintf( stdout, "j0             : %f\n", f1);

  f1 = j1 (1.2);
  fprintf( stdout, "j1             : %f\n", f1);

  f1 = jn (2,1.2);
  fprintf( stdout, "jn             : %f\n", f1);

  f1 = ldexp (1.2,3);
  fprintf( stdout, "ldexp          : %f\n", f1);

  f1 = lgamma (42.0);
  fprintf( stdout, "lgamma         : %f\n", f1);

  f1 = llrint (-0.5);
  fprintf( stdout, "llrint         : %f\n", f1);
  f1 = llrint (0.5);
  fprintf( stdout, "llrint         : %f\n", f1);

  f1 = llround (-0.5);
  fprintf( stdout, "lround         : %f\n", f1);
  f1 = llround (0.5);
  fprintf( stdout, "lround         : %f\n", f1);

  f1 = log (42.0);
  fprintf( stdout, "log            : %f\n", f1);

  f1 = log10 (42.0);
  fprintf( stdout, "log10          : %f\n", f1);

  f1 = log1p (42.0);
  fprintf( stdout, "log1p          : %f\n", f1);

  f1 = log2 (42.0);
  fprintf( stdout, "log2           : %f\n", f1);

  f1 = logb (42.0);
  fprintf( stdout, "logb           : %f\n", f1);

  f1 = lrint (-0.5);
  fprintf( stdout, "lrint          : %f\n", f1);
  f1 = lrint (0.5);
  fprintf( stdout, "lrint          : %f\n", f1);

  f1 = lround (-0.5);
  fprintf( stdout, "lround         : %f\n", f1);
  f1 = lround (0.5);
  fprintf( stdout, "lround         : %f\n", f1);

  f1 = modf (42.0,&f2);
  fprintf( stdout, "lmodf          : %f\n", f1);

  f1 = nan ("");
  fprintf( stdout, "nan            : %f\n", f1);

  f1 = nearbyint (1.5);
  fprintf( stdout, "nearbyint      : %f\n", f1);

  f1 = nextafter (1.5,2.0);
  fprintf( stdout, "nextafter      : %f\n", f1);

  f1 = pow (3.01, 2.0);
  fprintf( stdout, "pow            : %f\n", f1);

  f1 = remainder (3.01,2.0);
  fprintf( stdout, "remainder      : %f\n", f1);

  f1 = remquo (29.0,3.0,&i1);
  fprintf( stdout, "remquo         : %f\n", f1);

  f1 = rint (0.5);
  fprintf( stdout, "rint           : %f\n", f1);
  f1 = rint (-0.5);
  fprintf( stdout, "rint           : %f\n", f1);

  f1 = round (0.5);
  fprintf( stdout, "round          : %f\n", f1);
  f1 = round (-0.5);
  fprintf( stdout, "round          : %f\n", f1);

  f1 = scalbln (1.2,3);
  fprintf( stdout, "scalbln        : %f\n", f1);

  f1 = scalbn (1.2,3);
  fprintf( stdout, "scalbn         : %f\n", f1);

  /* no type-specific variant */
  i1 = signbit(1.0);
  fprintf( stdout, "signbit        : %i\n", i1);

  f1 = sin (M_PI_4);
  fprintf( stdout, "sin            : %f\n", f1);

  f1 = sinh (M_PI_4);
  fprintf( stdout, "sinh           : %f\n", f1);

  f1 = sqrt (9.0);
  fprintf( stdout, "sqrt           : %f\n", f1);

  f1 = tan (M_PI_4);
  fprintf( stdout, "tan            : %f\n", f1);

  f1 = tanh (M_PI_4);
  fprintf( stdout, "tanh           : %f\n", f1);

  f1 = tgamma (2.1);
  fprintf( stdout, "tgamma         : %f\n", f1);

  f1 = trunc (3.5);
  fprintf( stdout, "trunc          : %f\n", f1);

  f1 = y0 (1.2);
  fprintf( stdout, "y0             : %f\n", f1);

  f1 = y1 (1.2);
  fprintf( stdout, "y1             : %f\n", f1);

  f1 = yn (3,1.2);
  fprintf( stdout, "yn             : %f\n", f1);
#endif
}
Exemplo n.º 11
0
int main() {
    /*
    # Math errors

    # Errors

        The following errors exist for the standard library functions.

        # Domain error

            Value outside of function domain. E.g.: `sqrt(-1.0)`.

            TODO undefined or implementation defined?

            Detection: if `math_errhandling & MATH_ERRNO != 0`, `errno = ERANGE`
            and a "divide-by-zero" floating point exception is raised.

        # Pole error

            Function has a pole at a point. Ex: `log(0.0)`, `tgamma(-1.0)`.

            Return value: HUGE_VAL.

            Detection if `math_errhandling & MATH_ERRNO != 0`, `errno = ERANGE`
            and a "divide-by-zero" floating point exception is raised.

        # Range errors

            Occur if the result is too large or too small to fint into the return type.

            There are two types of range errors overflow and underflow.

            In both cases, if `math_errhandling & MATH_ERRNO != 0`,
            `errno = ERANGE` and a "divide-by-zero" floating point exception is raised.

            # Overflow

                For exapmle, around poles, functions can have arbitrarily large values,
                so it is possible that for a given input close enough to the pole that the output is too large to reprent.

                Return value: HUGE_VAL, HUGE_VALF, or HUGE_VALL, acording to function's return type.

            # Underflow

                The output is too small to represent

                Return value: an implementation-defined value whose magnitude is no greater than the smallest
                normalized positive number in the specified type;
    */
    printf("math_errhandling & MATH_ERRNO = %d\n", math_errhandling & MATH_ERRNO);

    /*
    # fabs

        Floating point abs.

        Integer version is in stdlib
    */
    {
        /* Absolute values, float version: */
        assert(fabsl(-1.1) == 1.1);
    }

#if __STDC_VERSION__ >= 199901L
    /*
    # fminl

    # fmaxl

        Max and min for floats.
    */
    {
        assert(fminl(0.1, 0.2) == 0.1);
        assert(fmaxl(0.1, 0.2) == 0.2);
    }
#endif

    /*
    # Rounding
    */
    {
        /*
        # floor

        # ceil
        */
        {
            assert(fabs(floor(0.5) - 0.0) < ERR);
            assert(fabs(ceil(0.5)  - 1.0) < ERR);
        }

        /*
        # trunc

            Never raises any errors because the new result always fits in the data type (magnitide decresases).
        */
        {
            assert(fabs(trunc(1.5)  -  1.0) < ERR);
            assert(fabs(trunc(-1.5) - -1.0) < ERR);
        }

        /*
        # round

            Away from 0 on mid case.
        */
        {
            assert(fabs(round( 1.25) -  1.0) < ERR);
            assert(fabs(round( 1.5 ) -  2.0) < ERR);
            assert(fabs(round( 1.75) -  2.0) < ERR);
            assert(fabs(round(-1.5 ) - -2.0) < ERR);
        }

        /*
        # modf

            Decompose into fraction and integer parts.
        */
        {
            double d;
            assert(fabs(modf(12.34, &d) -  0.34) < ERR);
            assert(fabs(d               - 12.0 ) < ERR);
        }

        /*
        # frexp

            Decompose into:

            - integer exponent
            - normalized mantissa, a fraction between 0.5 (inclusive) and 1.0 (exclusive)

            Guaranteed to power of 2 representation,
            even though this is not true for floating point?
            E.g. FLT_RADIX macros indicate it.
        */
        {
            int i;

            /* 1.5 = 0.75 * 2^1 */
            assert(frexp(1.5, &i) == 0.75);
            assert(i == 1);

            /* 3.0 = 0.75 * 2^2 */
            assert(frexp(3.0, &i) == 0.75);
            assert(i == 2);
        }
    }

    /*
    # fma

        Fused multiple add or floating point multiply and add.

        Does addition and multiplication on one operation,
        with a single rounding, reduncing rounding errors.

        Has hardware implementations on certain platforms.
    */
    {
        assert(fabs(fma(2.0, 3.0, 4.0) - (2.0 * 3.0 + 4.0)) < ERR);
    }

    /* # Exponential functions */
    {
        /* # exp */
        {
            assert(fabs(exp(1.0) - 2.71) < 0.01);
        }

        /*
        # ln

            See log.

        # log

            Calculates the ln.
        */
        {
            assert(fabs(log(exp(1.0)) - 1.0) < ERR);
            assert(fabs(log2(8.0)     - 3.0) < ERR);
            assert(fabs(log10(100.0)  - 2.0) < ERR);
        }

        /*
        # sqrt

            Range is positive or zero. Negatives are a range error.

            To get complex on negative values, use `csqrt`.
        */
        {
            assert(fabs(sqrt(4.0) - 2.0) < ERR);

            /* GCC 4.7 -O3 is smart enough to see that this is bad: */
            {
                float f = -4.0;
                /*printf("sqrt(-4.0) = %f\n", sqrt(f));*/
            }

            {
                float f;
                volatile float g;

                f = -4.0;
                errno = 0;
                g = sqrt(f);
                if (math_errhandling & MATH_ERRNO)
                    assert(errno == EDOM);
                printf("sqrt(-4.0) = %f\n", f);
            }
        }

#if __STDC_VERSION__ >= 199901L
        /*
        # hypot

            Hypotenuse: sqrt(x^2 + y^2)
        */
        {
            assert(fabs(hypot(3.0, 4.0) - 5.0) < ERR);
        }
#endif

#if __STDC_VERSION__ >= 199901L
        /*
        # cbrt

            CuBe RooT
        */
        {
            assert(fabs(cbrt(8.0 ) -  2.0) < ERR);
            assert(fabs(cbrt(-8.0) - -2.0) < ERR);
        }
#endif

        /* # pow */
        {
            assert(fabs(pow(2.0, 3.0) - 8.0 ) < ERR);
        }
    }

    /* # trig */
    {
        float f = sin(0.2);
        assert(fabs(sin(0.0) - 0.0) < ERR);
        assert(fabs(cos(0.0) - 1.0) < ERR);

        /*
        # PI

            There is no predefined macro for PI. TODO0 why not? so convenient...

            This is a standard way to get PI.

            The only problem is a possible slight calculation overhead.
            But don't worry much about it. For example in gcc 4.7, even with `gcc -O0` trigonometric functions
            are calculated at compile time and stored in the program text.
        */
        {
            assert(fabs(acos(-1.0) - 3.14)    < 0.01);
        }
    }

    /* # erf: TODO0 understand */

    /*
    # factorial

        There seems to be no integer factorial function,
        but `gamma(n+1)` coincides with the factorials of `n` on the positive integers,
        and may be faster to compute via analytic approximations that can be done to gamma
        and/or via a hardware implementation, so just use gamma.

    # gamma

        Wiki link: <http://en.wikipedia.org/wiki/Gamma_function>

        Extension of the factorials to the real numbers because:

        - on the positive integergs:

            gamma(n+1) == n!

        - on the positive reals:

            gamma(x+1) == x * gamma(x)

        Has a holomorphic continuation to all imaginary plane, with poles on 0 and negative integers.

        Implemented in C as `tgamma`.

    # tgamma

        True Gamma function. TODO0 Why True?

        Computes the gamma function.

        ANSI C says that it gives either domain or pole error on the negative integers.

    # lgamma

        lgamma = ln tgamma
    */
    {
        assert(fabs(tgamma(5.0) - 4*3*2) < ERR);
        assert(fabs(tgamma(3.5) - 2.5*tgamma(2.5)) < ERR);

        errno = 0;
        volatile double d = tgamma(-1.0);
        if (math_errhandling & MATH_ERRNO) {
            if (errno == ERANGE)
                assert(d == HUGE_VAL);
            else
                assert(errno == EDOM);
        }

        assert(fabs(lgamma(3.5) - log(tgamma(3.5))) < ERR);
    }

    /* Floating point manipulation functions. */
    {
        /*
        # ldexp

            ldexp(x, y) = x * (2^y)
        */
        {
            assert(fabs(ldexp(1.5, 2.0) - 6.0) < ERR);
        }

        /*
        # nextafter

            Return the next representable value in a direction.

            If both arguments equal, return them.

        # nexttowards

            TODO diff from nextafter
        */
        {
            printf("nexttowards(0.0, 1.0) = %a\n", nexttoward(0.0, 1.0));
            assert(nexttoward(0.0, 0.0) == 0.0);
            printf("nextafter  (0.0, 1.0) = %a\n", nextafter(0.0, 1.0));
        }
    }

    /*
    # Division by 0

        Time to have some fun and do naughty things.

        The outcome of a division by zero depends on wether it is an integer of floating operation.

    # isfinite

    # isinf

    # isnan

    # isnormal

        TODO

    # fpclassify

        FP_INFINITE, FP_NAN, FP_NORMAL, FP_SUBNORMAL, FP_ZERO
    */
    {
        /*
        # floating point exception

            In x86, the following generates a floating point exception,
            which is handled by a floating point exception handler function.

            In Linux the default handler is implemented by the OS and sends a signal to our application,
            which if we don't catch will kill us.
        */
        if (0) {
            /* gcc 4.7 is smart enough to warn on literal division by 0: */
            {
                /*int i = 1 / 0;*/
            }

            /* gcc 4.7 is not smart enough to warn here: */
            {
                volatile int i = 0;
                printf("int 1/0 = %d\n", 1 / i);

                /* On gcc 4.7 with `-O3` this may not generate an exception, */
                /* as the compiler replaces 0 / X by 0. */
                printf("int 0/0 = %d\n", 0 / i);
            }
        }

        /*
        # HUGE_VAL

            Returned on overflow. TODO example.

            Can equal `INFINITY`.
        */
        {
            /* double */
            printf("HUGE_VAL = %f\n", HUGE_VAL);
            /* float */
            printf("HUGE_VALF = %f\n", HUGE_VALF);
            /* long double */
            printf("HUGE_VALL = %Lf\n", HUGE_VALL);
        }

        /*
        # INFINITY

            Result of operations such as:

                1.0 / 0.0

            Type: float.

            There are two infinities: positive and negative.

            It is possible that `INFINITY == HUGE_VALF`.
        */
        {
            /* [-]inf or [-]infinity implementation defined. */
            printf("INFINITY = %f\n", INFINITY);
            printf("-INFINITY = %f\n", -INFINITY);

            volatile float f = 0;
            assert(1 / f == INFINITY);
            assert(isinf(INFINITY));
            assert(!isnan(INFINITY));

            assert(INFINITY + INFINITY == INFINITY);
            assert(INFINITY + 1.0      == INFINITY);
            assert(INFINITY - 1.0      == INFINITY);
            assert(isnan(INFINITY - INFINITY));

            assert(INFINITY *  INFINITY ==  INFINITY);
            assert(INFINITY * -INFINITY == -INFINITY);
            assert(INFINITY *  2.0      ==  INFINITY);
            assert(INFINITY * -1.0      == -INFINITY);
            assert(isnan(INFINITY * 0.0));

            assert(1.0 / INFINITY == 0.0);
            assert(isnan(INFINITY / INFINITY));

            /* Comparisons with INFINITY all work as expected. */
            assert(INFINITY == INFINITY);
            assert(INFINITY != - INFINITY);
            assert(-INFINITY < - 1e100);
            assert(1e100 < INFINITY);
        }

        /*
        # NAN

            Not a number.

            Result of operations such as:

                0.0 / 0.0
                INFINITY - INFINITY
                INFINITY * 0.o
                INFINITY / INFINITY

            And any operation involving NAN.

            The sign of NAN has no meaning.
        */
        {
            /* [-]NAN or [-]NAN<more characters> implementation defined. */
            printf("NAN = %f\n", NAN);
            printf("-NAN = %f\n", -NAN);

            /* TODO why do both fail? */
            /*assert(0 / f == -NAN);*/
            /*assert(0 / f == NAN);*/

            volatile float f = 0;
            assert(isnan(0 / f));
            assert(isnan(NAN));
            assert(!isinf(NAN));

            assert(isnan(NAN));
            assert(isnan(NAN + 1.0));
            assert(isnan(NAN + INFINITY));
            assert(isnan(NAN + NAN));
            assert(isnan(NAN - 1.0));
            assert(isnan(NAN * 2.0));
            assert(isnan(NAN / 1.0));
            assert(isnan(INFINITY - INFINITY));
            assert(isnan(INFINITY * 0.0));
            assert(isnan(INFINITY / INFINITY));

            /*
            NAN is not ordered. any compairison to it yields false!

            This is logical since 0 is neither smaller, larger or equal to NAN.
            */
            {
                assert(!(0.0 < NAN));
                assert(!(0.0 > NAN));
                assert(!(0.0 == NAN));
            }
        }

#if __STDC_VERSION__ >= 199901L
        /*
        # isunordered

            Macro.

                isunordered(x, y)

            Equals:

                isnan(x) || isnan(y)

            Likely exists because it is possible to optimize it in x86:
            http://stackoverflow.com/questions/26053934/is-it-feasible-to-add-this-optimization-to-gcc?rq=1
        */
        {
            assert(!isunordered(1.0, 1.0));
            assert(isunordered(NAN, 1.0));
            assert(isunordered(1.0, NAN));
            assert(isunordered(NAN, NAN));
        }
#endif
    }

    /*
    # FLT_EVAL_METHOD

    # float_t

    # double_t
    */
    {
        printf("FLT_EVAL_METHOD = %d\n", FLT_EVAL_METHOD);
    }

    return EXIT_SUCCESS;
}
static void
avx_test ()
{
    __m128d source1, source2, dest;

    e.d[1] = s1[1];
    
    CMP(_CMP_EQ_OQ, !isunordered(s1[0], s2[0]) && s1[0] == s2[0]);
    CMP(_CMP_LT_OS, !isunordered(s1[0], s2[0]) && s1[0] < s2[0]);
    CMP(_CMP_LE_OS, !isunordered(s1[0], s2[0]) && s1[0] <= s2[0]);
    CMP(_CMP_UNORD_Q, isunordered(s1[0], s2[0]));
    CMP(_CMP_NEQ_UQ, isunordered(s1[0], s2[0]) || s1[0] != s2[0]);
    CMP(_CMP_NLT_US, isunordered(s1[0], s2[0]) || s1[0] >= s2[0]);
    CMP(_CMP_NLE_US, isunordered(s1[0], s2[0]) || s1[0] > s2[0]);
    CMP(_CMP_ORD_Q, !isunordered(s1[0], s2[0]));

    CMP(_CMP_EQ_UQ, isunordered(s1[0], s2[0]) || s1[0] == s2[0]);
    CMP(_CMP_NGE_US, isunordered(s1[0], s2[0]) || s1[0] < s2[0]);
    CMP(_CMP_NGT_US, isunordered(s1[0], s2[0]) || s1[0] <= s2[0]);

    CMP(_CMP_FALSE_OQ, 0);
    CMP(_CMP_NEQ_OQ, !isunordered(s1[0], s2[0]) && s1[0] != s2[0]);
    CMP(_CMP_GE_OS, !isunordered(s1[0], s2[0]) && s1[0] >= s2[0]);
    CMP(_CMP_GT_OS, !isunordered(s1[0], s2[0]) && s1[0] > s2[0]);
    CMP(_CMP_TRUE_UQ, 1);

    CMP(_CMP_EQ_OS, !isunordered(s1[0], s2[0]) && s1[0] == s2[0]);
    CMP(_CMP_LT_OQ, !isunordered(s1[0], s2[0]) && s1[0] < s2[0]);
    CMP(_CMP_LE_OQ, !isunordered(s1[0], s2[0]) && s1[0] <= s2[0]);
    CMP(_CMP_UNORD_S, isunordered(s1[0], s2[0]));
    CMP(_CMP_NEQ_US, isunordered(s1[0], s2[0]) || s1[0] != s2[0]);
    CMP(_CMP_NLT_UQ, isunordered(s1[0], s2[0]) || s1[0] >= s2[0]);
    CMP(_CMP_NLE_UQ, isunordered(s1[0], s2[0]) || s1[0] > s2[0]);
    CMP(_CMP_ORD_S, !isunordered(s1[0], s2[0]));
    CMP(_CMP_EQ_US, isunordered(s1[0], s2[0]) || s1[0] == s2[0]);
    CMP(_CMP_NGE_UQ, isunordered(s1[0], s2[0]) || s1[0] < s2[0]);
    CMP(_CMP_NGT_UQ, isunordered(s1[0], s2[0]) || s1[0] <= s2[0]);
    CMP(_CMP_FALSE_OS, 0);
    CMP(_CMP_NEQ_OS, !isunordered(s1[0], s2[0]) && s1[0] != s2[0]);
    CMP(_CMP_GE_OQ, !isunordered(s1[0], s2[0]) && s1[0] >= s2[0]);
    CMP(_CMP_GT_OQ, !isunordered(s1[0], s2[0]) && s1[0] > s2[0]);
    CMP(_CMP_TRUE_US, 1);
}
Exemplo n.º 13
0
static lisp_cell_t *subr_unordered(lisp_t *l, lisp_cell_t *args)
{
	UNUSED(l);
	double a = get_float(car(args)), b = get_float(CADR(args));
	return isunordered(a, b) ? gsym_tee() : gsym_nil();
}
Exemplo n.º 14
0
#include "util.h"

TYPE_ARITH(float_t);
TYPE_ARITH(double_t);

IDENT(fpclassify(0.0), int);
IDENT(isfinite(0.0), int);
IDENT(isgreater(0.0, 0.0), int);
IDENT(isgreaterequal(0.0, 0.0), int);
IDENT(isinf(0.0), int);
IDENT(isless(0.0, 0.0), int);
IDENT(islessequal(0.0, 0.0), int);
IDENT(islessgreater(0.0, 0.0), int);
IDENT(isnan(0.0), int);
IDENT(isnormal(0.0), int);
IDENT(isunordered(0.0, 0.0), int);
IDENT(signbit(0.0), int);

IDENT(M_E, double);
IDENT(M_LOG2E, double);
IDENT(M_LOG10E, double);
IDENT(M_LN2, double);
IDENT(M_LN10, double);
IDENT(M_PI, double);
IDENT(M_PI_2, double);
IDENT(M_PI_4, double);
IDENT(M_1_PI, double);
IDENT(M_2_PI, double);
IDENT(M_2_SQRTPI, double);
IDENT(M_SQRT2, double);
IDENT(M_SQRT1_2, double);