int matherr (struct exception* e) { const char *n; if (e->type != DOMAIN) return 0; n = e->name; if (__builtin_strcmp (n, "acos") == 0 || __builtin_strcmp (n, "asin") == 0) e->retval = __builtin_nan (""); else if (__builtin_strcmp (n, "atan2") == 0) { if (e->arg1 == 0 && e->arg2 == 0) { double nz; nz = -0.0; if (__builtin_memcmp (&e->arg2, &nz, sizeof (double)) != 0) e->retval = e->arg1; else e->retval = copysign (PI, e->arg1); } else return 0; } else if (__builtin_strcmp (n, "log") == 0 || __builtin_strcmp (n, "log10") == 0) e->retval = __builtin_nan (""); else if (__builtin_strcmp (n, "pow") == 0) { if (e->arg1 < 0) e->retval = __builtin_nan (""); else if (e->arg1 == 0 && e->arg2 == 0) e->retval = 1.0; else if (e->arg1 == 0 && e->arg2 < 0) { double i; if (modf (e->arg2, &i) == 0 && ((int64_t) i & 1) == 1) e->retval = copysign (__builtin_inf (), e->arg1); else e->retval = __builtin_inf (); } else return 0; } else if (__builtin_strcmp (n, "sqrt") == 0) { if (e->arg1 < 0) e->retval = __builtin_nan (""); else return 0; } else return 0; return 1; }
double _Complex __muldc3(double fa, double fb, double fc, double fd) { union ud ua, ub, uc, ud, ux, uy, uac, ubd, uad, ubc; ua.f = fa; ub.f = fb; uc.f = fc; ud.f = fd; uac.f = ua.f * uc.f; ubd.f = ub.f * ud.f; uad.f = ua.f * ud.f; ubc.f = ub.f * uc.f; ux.f=uac.f-ubd.f; uy.f=uad.f+ubc.f; if (DOUBLE_ISNAN(ux) && DOUBLE_ISNAN(uy)) { /* Recover infinities that computed as NaN+iNaN ... */ int recalc = 0; if (DOUBLE_ISINF(ua) || DOUBLE_ISINF(ub) ) { // z is infinite /* "Box" the infinity and change NaNs in the other factor to 0 */ ua.f = pcc_copysign(DOUBLE_ISINF(ua) ? 1.0 : 0.0, ua.f); ub.f = pcc_copysign(DOUBLE_ISINF(ub) ? 1.0 : 0.0, ub.f); if (DOUBLE_ISNAN(uc)) uc.f = pcc_copysign(0.0, uc.f); if (DOUBLE_ISNAN(ud)) ud.f = pcc_copysign(0.0, ud.f); recalc = 1; } if (DOUBLE_ISINF(uc) || DOUBLE_ISINF(ud) ) { // w is infinite /* "Box" the infinity and change NaNs in the other factor to 0 */ uc.f = pcc_copysign(DOUBLE_ISINF(uc) ? 1.0 : 0.0, uc.f); ud.f = pcc_copysign(DOUBLE_ISINF(ud) ? 1.0 : 0.0, ud.f); if (DOUBLE_ISNAN(ua)) ua.f = pcc_copysign(0.0, ua.f); if (DOUBLE_ISNAN(ub)) ub.f = pcc_copysign(0.0, ub.f); recalc = 1; } if (!recalc && (DOUBLE_ISINF(uac) || DOUBLE_ISINF(ubd) || DOUBLE_ISINF(uad) || DOUBLE_ISINF(ubc))) { /* Recover infinities from overflow by changing NaNs to 0 ... */ if (DOUBLE_ISNAN(ua)) ua.f = pcc_copysign(0.0, ua.f); if (DOUBLE_ISNAN(ub)) ub.f = pcc_copysign(0.0, ub.f); if (DOUBLE_ISNAN(uc)) uc.f = pcc_copysign(0.0, uc.f); if (DOUBLE_ISNAN(ud)) ud.f = pcc_copysign(0.0, ud.f); recalc = 1; } if (recalc) { ux.f = __builtin_inf() * ( ua.f * uc.f - ub.f * ud.f ); uy.f = __builtin_inf() * ( ua.f * ud.f + ub.f * uc.f ); } } return ux.f + 1.0iF * uy.f; }
namespace float_limits { // Use some GCC internal stuff here. constexpr float rl78_nan_flt = static_cast<float>(__builtin_nan("")); constexpr float rl78_inf_flt = static_cast<float>(__builtin_inf()); constexpr double rl78_nan_dbl = __builtin_nan(""); constexpr double rl78_inf_dbl = __builtin_inf(); constexpr long double rl78_nan_ldbl = static_cast<long double>(__builtin_nan("")); constexpr long double rl78_inf_ldbl = static_cast<long double>(__builtin_inf()); }
int main(int argc, char *argv[]) { INPUT_TYPE input[INPUT_SIZE]; int i, j; srand(42); // Initialize the input array with data of various sizes. for (i=0; i<INPUT_SIZE; ++i) input[i] = rand() & 0x3f; int64_t fixedInput = INT64_C(0x1234567890ABCDEF); double bestTime = __builtin_inf(); void *dummyp; for (j=0; j<1024; ++j) { uint64_t startTime = mach_absolute_time(); for (i=0; i<INPUT_SIZE; ++i) FUNCTION_NAME(fixedInput, input[i]); uint64_t endTime = mach_absolute_time(); double thisTime = intervalInCycles(startTime, endTime); bestTime = __builtin_fmin(thisTime, bestTime); // Move the stack alignment between trials to eliminate (mostly) aliasing effects dummyp = alloca(1); } printf("%16s: %f cycles.\n", LIBSTRING, bestTime / (double) INPUT_SIZE); return 0; }
int main() { test (34.0, __builtin_inf()); testf (34.0f, __builtin_inff()); testf (34.0l, __builtin_infl()); return 0; }
int main () { double nan = __builtin_nan (""); float nanf = __builtin_nanf (""); long double nanl = __builtin_nanl (""); double pinf = __builtin_inf (); float pinff = __builtin_inff (); long double pinfl = __builtin_infl (); if (__builtin_finite (pinf)) link_error (); if (__builtin_finitef (pinff)) link_error (); if (__builtin_finitel (pinfl)) link_error (); if (__builtin_finite (nan)) link_error (); if (__builtin_finitef (nanf)) link_error (); if (__builtin_finitel (nanl)) link_error (); if (!__builtin_finite (4.0)) link_error (); if (!__builtin_finitef (4.0)) link_error (); if (!__builtin_finitel (4.0)) link_error (); }
long double __truncl (long double x) { double xh, xl, hi, lo; ldbl_unpack (x, &xh, &xl); /* Return Inf, Nan, +/-0 unchanged. */ if (__builtin_expect (xh != 0.0 && __builtin_isless (__builtin_fabs (xh), __builtin_inf ()), 1)) { double orig_xh; /* Long double arithmetic, including the canonicalisation below, only works in round-to-nearest mode. */ /* Convert the high double to integer. */ orig_xh = xh; hi = ldbl_nearbyint (xh); /* Subtract integral high part from the value. */ xh -= hi; ldbl_canonicalize (&xh, &xl); /* Now convert the low double, adjusted for any remainder from the high double. */ lo = ldbl_nearbyint (xh); /* Adjust the result when the remainder is non-zero. nearbyint rounds values to the nearest integer, and values halfway between integers to the nearest even integer. floorl must round towards -Inf. */ xh -= lo; ldbl_canonicalize (&xh, &xl); if (orig_xh < 0.0) { if (xh > 0.0 || (xh == 0.0 && xl > 0.0)) lo += 1.0; } else { if (xh < 0.0 || (xh == 0.0 && xl < 0.0)) lo -= 1.0; } /* Ensure the final value is canonical. In certain cases, rounding causes hi,lo calculated so far to be non-canonical. */ xh = hi; xl = lo; ldbl_canonicalize (&xh, &xl); /* Ensure we return -0 rather than +0 when appropriate. */ if (orig_xh < 0.0) xh = -__builtin_fabs (xh); } return ldbl_pack (xh, xl); }
/* sqrt(x) < y is x >= 0 && x != +Inf, when y is large. */ double fn2 (void) { double r; r = __builtin_sqrt (E) < __builtin_inf (); return r; }
long double __truncl (long double x) { double xh, xl, hi, lo; ldbl_unpack (x, &xh, &xl); /* Return Inf, Nan, +/-0 unchanged. */ if (__builtin_expect (xh != 0.0 && __builtin_isless (__builtin_fabs (xh), __builtin_inf ()), 1)) { hi = __trunc (xh); if (hi != xh) { /* The high part is not an integer; the low part does not affect the result. */ xh = hi; xl = 0; } else { /* The high part is a nonzero integer. */ lo = xh > 0 ? __floor (xl) : __ceil (xl); xh = hi; xl = lo; ldbl_canonicalize_int (&xh, &xl); } } return ldbl_pack (xh, xl); }
int main (void) { const double inf = __builtin_inf (); const double nan = __builtin_nan (""); volatile double d; __int128 i; d = INT128_MIN; CHECK_BOUNDARY (i, d); d = 0.0; CHECK_BOUNDARY (i, d); d = INT128_MAX; CHECK_BOUNDARY (i, d); CHECK_NONNUMBERS (i); unsigned __int128 u; d = UINT128_MAX; CHECK_BOUNDARY (u, d); d = 0.0; CHECK_BOUNDARY (u, d); CHECK_NONNUMBERS (u); return 0; }
int __fpclassifyd( double x ) { x = __builtin_fabs(x); if( EXPECT_FALSE( x == 0.0 ) ) return FP_ZERO; if( EXPECT_FALSE( x < 0x1.0p-1022 ) ) return FP_SUBNORMAL; if( EXPECT_TRUE( x < __builtin_inf() ) ) return FP_NORMAL; if( EXPECT_TRUE( x == __builtin_inf() ) ) return FP_INFINITE; return FP_NAN; }
long double __roundl (long double x) { double xh, xl, hi, lo; ldbl_unpack (x, &xh, &xl); /* Return Inf, Nan, +/-0 unchanged. */ if (__builtin_expect (xh != 0.0 && __builtin_isless (__builtin_fabs (xh), __builtin_inf ()), 1)) { hi = __round (xh); if (hi != xh) { /* The high part is not an integer; the low part only affects the result if the high part is exactly half way between two integers and the low part is nonzero with the opposite sign. */ if (fabs (hi - xh) == 0.5) { if (xh > 0 && xl < 0) xh = hi - 1; else if (xh < 0 && xl > 0) xh = hi + 1; else xh = hi; } else xh = hi; xl = 0; } else { /* The high part is a nonzero integer. */ lo = __round (xl); if (fabs (lo - xl) == 0.5) { if (xh > 0 && xl < 0) xl = lo + 1; else if (xh < 0 && lo > 0) xl = lo - 1; else xl = lo; } else xl = lo; xh = hi; ldbl_canonicalize_int (&xh, &xl); } } else /* Quiet signaling NaN arguments. */ xh += xh; return ldbl_pack (xh, xl); }
inline static double minus_inf() { #if defined(__GNUC__) return -__builtin_inf(); #else static const double plus_zero = +0.0; static const double minus_one = -1.0; return plus_zero / minus_one; #endif }
long double __roundl (long double x) { double xh, xl, hi, lo; ldbl_unpack (x, &xh, &xl); /* Return Inf, Nan, +/-0 unchanged. */ if (__builtin_expect (xh != 0.0 && __builtin_isless (__builtin_fabs (xh), __builtin_inf ()), 1)) { double orig_xh; /* Long double arithmetic, including the canonicalisation below, only works in round-to-nearest mode. */ /* Convert the high double to integer. */ orig_xh = xh; hi = ldbl_nearbyint (xh); /* Subtract integral high part from the value. */ xh -= hi; ldbl_canonicalize (&xh, &xl); /* Now convert the low double, adjusted for any remainder from the high double. */ lo = ldbl_nearbyint (xh); /* Adjust the result when the remainder is exactly 0.5. nearbyint rounds values halfway between integers to the nearest even integer. roundl must round away from zero. Also correct cases where nearbyint returns an incorrect value for LO. */ xh -= lo; ldbl_canonicalize (&xh, &xl); if (xh == 0.5) { if (xl > 0.0 || (xl == 0.0 && orig_xh > 0.0)) lo += 1.0; } else if (-xh == 0.5) { if (xl < 0.0 || (xl == 0.0 && orig_xh < 0.0)) lo -= 1.0; } /* Ensure the final value is canonical. In certain cases, rounding causes hi,lo calculated so far to be non-canonical. */ xh = hi; xl = lo; ldbl_canonicalize (&xh, &xl); } return ldbl_pack (xh, xl); }
static int do_test (void) { int result = 0; if (FLT_EVAL_METHOD == 1 || FLT_EVAL_METHOD == 2 || FLT_EVAL_METHOD > 32) { /* Excess precision for float. */ if (iseqsig (1.0f, 1.0f + (float) DBL_EPSILON)) { puts ("iseqsig removes excess precision float -> double"); result = 1; } else puts ("iseqsig preserves excess precision float -> double"); if (iseqsig (__builtin_inff (), FLT_MAX * FLT_MAX)) { puts ("iseqsig removes excess range float -> double"); result = 1; } else puts ("iseqsig preserves excess range float -> double"); } if (FLT_EVAL_METHOD == 2 || FLT_EVAL_METHOD > 64) { /* Excess precision for float and double. */ if (iseqsig (1.0f, 1.0f + (float) LDBL_EPSILON)) { puts ("iseqsig removes excess precision float -> long double"); result = 1; } else puts ("iseqsig preserves excess precision float -> long double"); if (iseqsig (1.0, 1.0 + (double) LDBL_EPSILON)) { puts ("iseqsig removes excess precision double -> long double"); result = 1; } else puts ("iseqsig preserves excess precision double -> long double"); if (LDBL_MAX_EXP >= 2 * DBL_MAX_EXP) { if (iseqsig (__builtin_inf (), DBL_MAX * DBL_MAX)) { puts ("iseqsig removes excess range double -> long double"); result = 1; } else puts ("iseqsig preserves excess range double -> long double"); } } return result; }
int test_main (void) { json_ctx_t json_ctx; size_t i; bench_start (); json_init (&json_ctx, 2, stdout); json_attr_object_begin (&json_ctx, TEST_NAME); /* Create 2 test arrays, one with 10% zeroes, 10% negative values, 79% positive values and 1% infinity/NaN. The other contains 50% inf, 50% NaN. This relies on rand behaving correctly. */ for (i = 0; i < SIZE; i++) { int x = rand () & 255; arr1[i] = (x < 25) ? 0.0 : ((x < 50) ? -1 : 100); if (x == 255) arr1[i] = __builtin_inf (); if (x == 254) arr1[i] = __builtin_nan ("0"); arr2[i] = (x < 128) ? __builtin_inf () : __builtin_nan ("0"); } for (i = 0; i < sizeof (test_list) / sizeof (test_list[0]); i++) { json_attr_object_begin (&json_ctx, test_list[i].name); do_one_test (&json_ctx, test_list[i].fn, arr2, SIZE, "inf/nan"); json_attr_object_end (&json_ctx); } for (i = 0; i < sizeof (test_list) / sizeof (test_list[0]); i++) { json_attr_object_begin (&json_ctx, test_list[i].name); do_one_test (&json_ctx, test_list[i].fn, arr1, SIZE, "normal"); json_attr_object_end (&json_ctx); } json_attr_object_end (&json_ctx); return 0; }
int main() { /* * Return inf means infinity,and return NAN means not a number. */ printf("The __builtin_inf():[%lf]\n", __builtin_inf()); printf("The __builtin_inff():[%f]\n", __builtin_inff()); printf("The __builtin_infl:[%Lf]\n", __builtin_infl()); return 0; }
void test(double f, double i) { if (f == __builtin_inf()) abort (); if (f == -__builtin_inf()) abort (); if (i == -__builtin_inf()) abort (); if (i != __builtin_inf()) abort (); if (f >= __builtin_inf()) abort (); if (f > __builtin_inf()) abort (); if (i > __builtin_inf()) abort (); if (f <= -__builtin_inf()) abort (); if (f < -__builtin_inf()) abort (); }
int main() { volatile float a = __builtin_nanf(""); if (__builtin_isfinite(a)) { return 1; } volatile float b = __builtin_inff(); if (__builtin_isfinite(b)) { return 1; } volatile double c = __builtin_nan(""); if (__builtin_isfinite(c)) { return 1; } volatile double d = __builtin_inf(); if (__builtin_isfinite(d)) { return 1; } #ifdef __clang__ // TODO: dragonegg uses native calls which do not work with X86_FP80 volatile long double e = __builtin_nanl(""); if (__builtin_isfinite(e)) { return 1; } volatile long double f = __builtin_infl(); if (__builtin_isfinite(f)) { return 1; } #endif volatile float g = 0; if (!__builtin_isfinite(g)) { return 1; } volatile double h = 0; if (!__builtin_isfinite(h)) { return 1; } #ifdef __clang__ // TODO: dragonegg uses native calls which do not work with X86_FP80 volatile long double i = 0; if (!__builtin_isfinite(i)) { return 1; } #endif return 0; }
int main() { #ifndef __SPU__ /* The SPU single-precision floating point format does not support Inf. */ float fi = __builtin_inff(); #endif double di = __builtin_inf(); long double li = __builtin_infl(); float fh = __builtin_huge_valf(); double dh = __builtin_huge_val(); long double lh = __builtin_huge_vall(); #ifndef __SPU__ if (fi + fi != fi) abort (); #endif if (di + di != di) abort (); if (li + li != li) abort (); #ifndef __SPU__ if (fi != fh) abort (); #endif if (di != dh) abort (); if (li != lh) abort (); #ifndef __SPU__ if (fi <= 0) abort (); #endif if (di <= 0) abort (); if (li <= 0) abort (); return 0; }
int main () { double pinf = __builtin_inf (); float pinff = __builtin_inff (); long double pinfl = __builtin_infl (); if (__builtin_isinf (pinf) != 1) link_error (); if (__builtin_isinf (pinff) != 1) link_error (); if (__builtin_isinff (pinff) != 1) link_error (); if (__builtin_isinf (pinfl) != 1) link_error (); if (__builtin_isinfl (pinfl) != 1) link_error (); if (__builtin_isinf (-pinf) != -1) link_error (); if (__builtin_isinf (-pinff) != -1) link_error (); if (__builtin_isinff (-pinff) != -1) link_error (); if (__builtin_isinf (-pinfl) != -1) link_error (); if (__builtin_isinfl (-pinfl) != -1) link_error (); if (__builtin_isinf (4.0)) link_error (); if (__builtin_isinf (4.0)) link_error (); if (__builtin_isinff (4.0)) link_error (); if (__builtin_isinf (4.0)) link_error (); if (__builtin_isinfl (4.0)) link_error (); }
int main () { pinf = __builtin_inf (); ninf = -__builtin_inf (); NaN = __builtin_nan (""); iuneq (ninf, pinf, 0); iuneq (NaN, NaN, 1); iuneq (pinf, ninf, 0); iuneq (1, 4, 0); iuneq (3, 3, 1); iuneq (5, 2, 0); ieq (1, 4, 0); ieq (3, 3, 1); ieq (5, 2, 0); iltgt (ninf, pinf, 1); iltgt (NaN, NaN, 0); iltgt (pinf, ninf, 1); iltgt (1, 4, 1); iltgt (3, 3, 0); iltgt (5, 2, 1); ine (1, 4, 1); ine (3, 3, 0); ine (5, 2, 1); iunlt (NaN, ninf, 1); iunlt (pinf, NaN, 1); iunlt (pinf, ninf, 0); iunlt (pinf, pinf, 0); iunlt (ninf, ninf, 0); iunlt (1, 4, 1); iunlt (3, 3, 0); iunlt (5, 2, 0); ilt (1, 4, 1); ilt (3, 3, 0); ilt (5, 2, 0); iunle (NaN, ninf, 1); iunle (pinf, NaN, 1); iunle (pinf, ninf, 0); iunle (pinf, pinf, 1); iunle (ninf, ninf, 1); iunle (1, 4, 1); iunle (3, 3, 1); iunle (5, 2, 0); ile (1, 4, 1); ile (3, 3, 1); ile (5, 2, 0); iungt (NaN, ninf, 1); iungt (pinf, NaN, 1); iungt (pinf, ninf, 1); iungt (pinf, pinf, 0); iungt (ninf, ninf, 0); iungt (1, 4, 0); iungt (3, 3, 0); iungt (5, 2, 1); igt (1, 4, 0); igt (3, 3, 0); igt (5, 2, 1); iunge (NaN, ninf, 1); iunge (pinf, NaN, 1); iunge (ninf, pinf, 0); iunge (pinf, pinf, 1); iunge (ninf, ninf, 1); iunge (1, 4, 0); iunge (3, 3, 1); iunge (5, 2, 1); ige (1, 4, 0); ige (3, 3, 1); ige (5, 2, 1); return 0; }
int fpu_post_test_math6 (void) { pinf = __builtin_inf (); ninf = -__builtin_inf (); NaN = __builtin_nan (""); iuneq (ninf, pinf, 0); iuneq (NaN, NaN, 1); iuneq (pinf, ninf, 0); iuneq (1, 4, 0); iuneq (3, 3, 1); iuneq (5, 2, 0); ieq (1, 4, 0); ieq (3, 3, 1); ieq (5, 2, 0); iltgt (ninf, pinf, 1); iltgt (NaN, NaN, 0); iltgt (pinf, ninf, 1); iltgt (1, 4, 1); iltgt (3, 3, 0); iltgt (5, 2, 1); ine (1, 4, 1); ine (3, 3, 0); ine (5, 2, 1); iunlt (NaN, ninf, 1); iunlt (pinf, NaN, 1); iunlt (pinf, ninf, 0); iunlt (pinf, pinf, 0); iunlt (ninf, ninf, 0); iunlt (1, 4, 1); iunlt (3, 3, 0); iunlt (5, 2, 0); ilt (1, 4, 1); ilt (3, 3, 0); ilt (5, 2, 0); iunle (NaN, ninf, 1); iunle (pinf, NaN, 1); iunle (pinf, ninf, 0); iunle (pinf, pinf, 1); iunle (ninf, ninf, 1); iunle (1, 4, 1); iunle (3, 3, 1); iunle (5, 2, 0); ile (1, 4, 1); ile (3, 3, 1); ile (5, 2, 0); iungt (NaN, ninf, 1); iungt (pinf, NaN, 1); iungt (pinf, ninf, 1); iungt (pinf, pinf, 0); iungt (ninf, ninf, 0); iungt (1, 4, 0); iungt (3, 3, 0); iungt (5, 2, 1); igt (1, 4, 0); igt (3, 3, 0); igt (5, 2, 1); iunge (NaN, ninf, 1); iunge (pinf, NaN, 1); iunge (ninf, pinf, 0); iunge (pinf, pinf, 1); iunge (ninf, ninf, 1); iunge (1, 4, 0); iunge (3, 3, 1); iunge (5, 2, 1); ige (1, 4, 0); ige (3, 3, 1); ige (5, 2, 1); if (failed) { post_log ("Error in FPU math6 test\n"); return -1; } return 0; }
// RUN: %clang_cc1 -fsyntax-only -verify %s // Math stuff double g0 = __builtin_huge_val(); float g1 = __builtin_huge_valf(); long double g2 = __builtin_huge_vall(); double g3 = __builtin_inf(); float g4 = __builtin_inff(); long double g5 = __builtin_infl(); double g6 = __builtin_nan(""); float g7 = __builtin_nanf(""); long double g8 = __builtin_nanl(""); // GCC constant folds these too (via native strtol): //double g6_1 = __builtin_nan("1"); //float g7_1 = __builtin_nanf("1"); //long double g8_1 = __builtin_nanl("1"); // APFloat doesn't have signalling NaN functions. //double g9 = __builtin_nans(""); //float g10 = __builtin_nansf(""); //long double g11 = __builtin_nansl(""); //int g12 = __builtin_abs(-12); double g13 = __builtin_fabs(-12.); double g13_0 = __builtin_fabs(-0.); double g13_1 = __builtin_fabs(-__builtin_inf());
void bar() { /* An argument of NaN is not evaluated at compile-time. */ #ifndef __SPU__ foof (__builtin_exp2f (__builtin_nanf(""))); #endif foo (__builtin_exp2 (__builtin_nan(""))); fool (__builtin_exp2l (__builtin_nanl(""))); /* An argument of Inf/-Inf is not evaluated at compile-time. */ #ifndef __SPU__ foof (__builtin_exp2f (__builtin_inff())); #endif foo (__builtin_exp2 (__builtin_inf())); fool (__builtin_exp2l (__builtin_infl())); #ifndef __SPU__ foof (__builtin_exp2f (-__builtin_inff())); #endif foo (__builtin_exp2 (-__builtin_inf())); fool (__builtin_exp2l (-__builtin_infl())); /* Result overflows MPFR, which in version 2.2.x has 30 exponent bits. */ TESTIT (exp2, 0x1p50); /* Result underflows MPFR, which in version 2.2.x has 30 exponent bits. */ TESTIT (exp2, -0x1p50); /* Result overflows GCC's REAL_VALUE_TYPE, which has 26 exponent bits. */ TESTIT (exp2, 0x1p28); /* Result underflows GCC's REAL_VALUE_TYPE, which has 26 exponent bits. */ TESTIT (exp2, -0x1p28); /* Result overflows (even an extended) C double's mode. */ TESTIT (exp2, 0x1p24); /* Result underflows (even an extended) C double's mode. */ TESTIT (exp2, -0x1p24); /* Ensure that normal arguments/results are folded. */ TESTIT (exp2, 1.5); TESTIT (exp2, -1.5); /* The asin arg must be [-1 ... 1] inclusive. */ TESTIT (asin, -1.5); TESTIT (asin, 1.5); /* The acos arg must be [-1 ... 1] inclusive. */ TESTIT (acos, -1.5); TESTIT (acos, 1.5); /* The acosh arg must be [1 ... Inf] inclusive. */ TESTIT (acosh, 0.5); /* The atanh arg must be [-1 ... 1] EXclusive. */ TESTIT (atanh, -1.0); TESTIT (atanh, 1.0); /* The log* arg must be [0 ... Inf] EXclusive. */ TESTIT (log, -1.0); TESTIT (log, 0.0); TESTIT (log, -0.0); TESTIT (log2, -1.0); TESTIT (log2, 0.0); TESTIT (log2, -0.0); TESTIT (log10, -1.0); TESTIT (log10, 0.0); TESTIT (log10, -0.0); /* The log1p arg must be [-1 ... Inf] EXclusive. */ TESTIT (log1p, -2.0); TESTIT (log1p, -1.0); /* The tgamma arg errors with zero or negative integers. */ TESTIT (tgamma, 0.0); TESTIT (tgamma, -0.0); TESTIT (tgamma, -1.0); TESTIT (tgamma, -2.0); TESTIT (tgamma, -3.0); /* An argument of NaN is not evaluated at compile-time. */ #ifndef __SPU__ foof (__builtin_powf (__builtin_nanf(""), 2.5F)); #endif foo (__builtin_pow (__builtin_nan(""), 2.5)); fool (__builtin_powl (__builtin_nanl(""), 2.5L)); #ifndef __SPU__ foof (__builtin_powf (2.5F, __builtin_nanf(""))); #endif foo (__builtin_pow (2.5, __builtin_nan(""))); fool (__builtin_powl (2.5L, __builtin_nanl(""))); /* An argument of Inf/-Inf is not evaluated at compile-time. */ #ifndef __SPU__ foof (__builtin_powf (__builtin_inff(), 2.5F)); #endif foo (__builtin_pow (__builtin_inf(), 2.5)); fool (__builtin_powl (__builtin_infl(), 2.5L)); #ifndef __SPU__ foof (__builtin_powf (-__builtin_inff(), 2.5F)); #endif foo (__builtin_pow (-__builtin_inf(), 2.5)); fool (__builtin_powl (-__builtin_infl(), 2.5L)); #ifndef __SPU__ foof (__builtin_powf (2.5F, __builtin_inff())); #endif foo (__builtin_pow (2.5, __builtin_inf())); fool (__builtin_powl (2.5L, __builtin_infl())); #ifndef __SPU__ foof (__builtin_powf (2.5F, -__builtin_inff())); #endif foo (__builtin_pow (2.5, -__builtin_inf())); fool (__builtin_powl (2.5L, -__builtin_infl())); /* Check for Inv/NaN return values. */ TESTIT2 (pow, -0.0, -4.5); /* Returns Inf */ TESTIT2 (pow, 0.0, -4.5); /* Returns Inf */ TESTIT2 (pow, -3.0, -4.5); /* Returns NaN */ /* Check for overflow/underflow. */ foof (__builtin_powf (__FLT_MAX__, 3.5F)); foo (__builtin_pow (__DBL_MAX__, 3.5)); fool (__builtin_powl (__LDBL_MAX__, 3.5L)); TESTIT2 (pow, 2.0, 0x1p50); foof (__builtin_powf (__FLT_MAX__, -3.5F)); foo (__builtin_pow (__DBL_MAX__, -3.5)); fool (__builtin_powl (__LDBL_MAX__, -3.5L)); TESTIT2 (pow, 2.0, -0x1p50); /* The sqrt arg must be [0 ... Inf] inclusive. */ TESTIT (sqrt, -0.5); TESTIT (sqrt, -0.0); TESTIT (sqrt, 0.0); /* Check for overflow/underflow. */ /* These adjustments are too big. */ #define FLT_EXP_ADJ (2*(__FLT_MAX_EXP__-__FLT_MIN_EXP__)+1) #define DBL_EXP_ADJ (2*(__DBL_MAX_EXP__-__DBL_MIN_EXP__)+1) #define LDBL_EXP_ADJ (2*(__LDBL_MAX_EXP__-__LDBL_MIN_EXP__)+1) TESTIT2_I2 (ldexp, 1.0, __INT_MAX__); TESTIT2_I2 (ldexp, 1.0, -__INT_MAX__-1); TESTIT2_I2 (ldexp, -1.0, __INT_MAX__); TESTIT2_I2 (ldexp, -1.0, -__INT_MAX__-1); TESTIT2_I2ALL (ldexp, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__, DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ); TESTIT2_I2ALL (ldexp, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__, -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ); TESTIT2_I2ALL (ldexp, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__, __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__); TESTIT2_I2ALL (ldexp, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__, __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__); TESTIT2_I2 (scalbn, 1.0, __INT_MAX__); TESTIT2_I2 (scalbn, 1.0, -__INT_MAX__-1); TESTIT2_I2 (scalbn, -1.0, __INT_MAX__); TESTIT2_I2 (scalbn, -1.0, -__INT_MAX__-1); TESTIT2_I2ALL (scalbn, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__, DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ); TESTIT2_I2ALL (scalbn, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__, -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ); TESTIT2_I2ALL (scalbn, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__, __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__); TESTIT2_I2ALL (scalbn, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__, __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__); TESTIT2_I2 (scalbln, 1.0, __LONG_MAX__); TESTIT2_I2 (scalbln, 1.0, -__LONG_MAX__-1); TESTIT2_I2 (scalbln, -1.0, __LONG_MAX__); TESTIT2_I2 (scalbln, -1.0, -__LONG_MAX__-1); TESTIT2_I2ALL (scalbln, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__, DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ); TESTIT2_I2ALL (scalbln, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__, -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ); TESTIT2_I2ALL (scalbln, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__, __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__); TESTIT2_I2ALL (scalbln, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__, __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__); TESTIT (logb, 0.0); TESTIT (logb, -0.0); TESTIT (ilogb, 0.0); TESTIT (ilogb, -0.0); #ifndef __SPU__ foof (__builtin_ilogbf (__builtin_inff())); #endif foo (__builtin_ilogb (__builtin_inf())); fool (__builtin_ilogbl (__builtin_infl())); #ifndef __SPU__ foof (__builtin_ilogbf (-__builtin_inff())); #endif foo (__builtin_ilogb (-__builtin_inf())); fool (__builtin_ilogbl (-__builtin_infl())); #ifndef __SPU__ foof (__builtin_ilogbf (__builtin_nanf(""))); #endif foo (__builtin_ilogb (__builtin_nan(""))); fool (__builtin_ilogbl (__builtin_nanl(""))); #ifndef __SPU__ foof (__builtin_ilogbf (-__builtin_nanf(""))); #endif foo (__builtin_ilogb (-__builtin_nan(""))); fool (__builtin_ilogbl (-__builtin_nanl(""))); /* The y* arg must be [0 ... Inf] EXclusive. */ TESTIT (y0, -1.0); TESTIT (y0, 0.0); TESTIT (y0, -0.0); TESTIT (y1, -1.0); TESTIT (y1, 0.0); TESTIT (y1, -0.0); TESTIT2_I1 (yn, 2, -1.0); TESTIT2_I1 (yn, 2, 0.0); TESTIT2_I1 (yn, 2, -0.0); TESTIT2_I1 (yn, -3, -1.0); TESTIT2_I1 (yn, -3, 0.0); TESTIT2_I1 (yn, -3, -0.0); /* The second argument of remquo/remainder/drem must not be 0. */ TESTIT_REMQUO (1.0, 0.0); TESTIT_REMQUO (1.0, -0.0); TESTIT2 (remainder, 1.0, 0.0); TESTIT2 (remainder, 1.0, -0.0); TESTIT2 (drem, 1.0, 0.0); TESTIT2 (drem, 1.0, -0.0); /* The argument to lgamma* cannot be zero or a negative integer. */ TESTIT_REENT (lgamma, -4.0); /* lgamma_r */ TESTIT_REENT (lgamma, -3.0); /* lgamma_r */ TESTIT_REENT (lgamma, -2.0); /* lgamma_r */ TESTIT_REENT (lgamma, -1.0); /* lgamma_r */ TESTIT_REENT (lgamma, -0.0); /* lgamma_r */ TESTIT_REENT (lgamma, 0.0); /* lgamma_r */ TESTIT_REENT (gamma, -4.0); /* gamma_r */ TESTIT_REENT (gamma, -3.0); /* gamma_r */ TESTIT_REENT (gamma, -2.0); /* gamma_r */ TESTIT_REENT (gamma, -1.0); /* gamma_r */ TESTIT_REENT (gamma, -0.0); /* gamma_r */ TESTIT_REENT (gamma, 0.0); /* gamma_r */ }
int convert_infnan (st_parameter_dt *dtp, void *dest, const char *buffer, int length) { const char *s = buffer; int is_inf, plus = 1; if (*s == '+') s++; else if (*s == '-') { s++; plus = 0; } is_inf = *s == 'i'; switch (length) { case 4: if (is_inf) *((GFC_REAL_4*) dest) = plus ? __builtin_inff () : -__builtin_inff (); else *((GFC_REAL_4*) dest) = plus ? __builtin_nanf ("") : -__builtin_nanf (""); break; case 8: if (is_inf) *((GFC_REAL_8*) dest) = plus ? __builtin_inf () : -__builtin_inf (); else *((GFC_REAL_8*) dest) = plus ? __builtin_nan ("") : -__builtin_nan (""); break; #if defined(HAVE_GFC_REAL_10) case 10: if (is_inf) *((GFC_REAL_10*) dest) = plus ? __builtin_infl () : -__builtin_infl (); else *((GFC_REAL_10*) dest) = plus ? __builtin_nanl ("") : -__builtin_nanl (""); break; #endif #if defined(HAVE_GFC_REAL_16) # if defined(GFC_REAL_16_IS_FLOAT128) case 16: *((GFC_REAL_16*) dest) = __qmath_(strtoflt128) (buffer, NULL); break; # else case 16: if (is_inf) *((GFC_REAL_16*) dest) = plus ? __builtin_infl () : -__builtin_infl (); else *((GFC_REAL_16*) dest) = plus ? __builtin_nanl ("") : -__builtin_nanl (""); break; # endif #endif default: internal_error (&dtp->common, "Unsupported real kind during IO"); } return 0; }
/* { dg-do run } */ /* { dg-options "-O2 -fno-math-errno -fno-trapping-math -msse2 -mfpmath=sse" } */ /* { dg-require-effective-target sse2 } */ #include "sse2-check.h" double x[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(), -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023, /* +-DBL_MAX */ -0x1p-52, 0x1p-52, /* +-DBL_EPSILON */ /* nextafter/before 0.5, 1.0 and 1.5 */ 0x1.0000000000001p-1, 0x1.fffffffffffffp-2, 0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.8000000000001p+0, 0x1.7ffffffffffffp+0, -0.0, 0.0, -0.5, 0.5, -1.0, 1.0, -1.5, 1.5, -2.0, 2.0, -2.5, 2.5 }; #define NUM (sizeof(x)/sizeof(double)) double expect_round[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(), -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023, -0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 2.0, 1.0, -0.0, 0.0, -1.0, 1.0, -1.0, 1.0, -2.0, 2.0, -2.0, 2.0, -3.0, 3.0 }; double expect_rint[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(), -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023, -0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 2.0, 1.0, -0.0, 0.0, -0.0, 0.0, -1.0, 1.0, -2.0, 2.0, -2.0, 2.0, -2.0, 2.0 };
/* x <= +Inf is the same as x == x, i.e. !isnan(x). */ int fn5 (void) { return E <= __builtin_inf (); }
void foo(double x) { if (x > __builtin_inf()) link_error (); }
// RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic // Math stuff float g0 = __builtin_huge_val(); double g1 = __builtin_huge_valf(); long double g2 = __builtin_huge_vall(); float g3 = __builtin_inf(); double g4 = __builtin_inff(); long double g5 = __builtin_infl(); // GCC misc stuff extern int f(); int h0 = __builtin_types_compatible_p(int,float); //int h1 = __builtin_choose_expr(1, 10, f()); //int h2 = __builtin_expect(0, 0); int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f(); int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f(); int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f(); short somefunc(); short t = __builtin_constant_p(5353) ? 42 : somefunc();