// CHECK-LABEL: define void @bar( void bar() { float f; double d; long double ld; // LLVM's hex representation of float constants is really unfortunate; // basically it does a float-to-double "conversion" and then prints the // hex form of that. That gives us weird artifacts like exponents // that aren't numerically similar to the original exponent and // significand bit-patterns that are offset by three bits (because // the exponent was expanded from 8 bits to 11). // // 0xAE98 == 1010111010011000 // 0x15D3 == 1010111010011 f = __builtin_huge_valf(); // CHECK: float 0x7FF0000000000000 d = __builtin_huge_val(); // CHECK: double 0x7FF0000000000000 ld = __builtin_huge_vall(); // CHECK: x86_fp80 0xK7FFF8000000000000000 f = __builtin_nanf(""); // CHECK: float 0x7FF8000000000000 d = __builtin_nan(""); // CHECK: double 0x7FF8000000000000 ld = __builtin_nanl(""); // CHECK: x86_fp80 0xK7FFFC000000000000000 f = __builtin_nanf("0xAE98"); // CHECK: float 0x7FF815D300000000 d = __builtin_nan("0xAE98"); // CHECK: double 0x7FF800000000AE98 ld = __builtin_nanl("0xAE98"); // CHECK: x86_fp80 0xK7FFFC00000000000AE98 f = __builtin_nansf(""); // CHECK: float 0x7FF4000000000000 d = __builtin_nans(""); // CHECK: double 0x7FF4000000000000 ld = __builtin_nansl(""); // CHECK: x86_fp80 0xK7FFFA000000000000000 f = __builtin_nansf("0xAE98"); // CHECK: float 0x7FF015D300000000 d = __builtin_nans("0xAE98"); // CHECK: double 0x7FF000000000AE98 ld = __builtin_nansl("0xAE98");// CHECK: x86_fp80 0xK7FFF800000000000AE98 }
int main() { volatile float a = __builtin_nanf(""); if (!__builtin_isnan(a)) { return 1; } volatile float b = __builtin_nansf(""); if (!__builtin_isnan(b)) { return 1; } volatile double c = __builtin_nan(""); if (!__builtin_isnan(c)) { return 1; } volatile double d = __builtin_nans(""); if (!__builtin_isnan(d)) { return 1; } volatile long double e = __builtin_nanl(""); if (!__builtin_isnan(e)) { return 1; } volatile long double f = __builtin_nansl(""); if (!__builtin_isnan(f)) { return 1; } volatile float g = 0; if (__builtin_isnan(g)) { return 1; } volatile double h = 0; if (__builtin_isnan(h)) { return 1; } volatile long double i = 0; if (__builtin_isnan(i)) { return 1; } return 0; }
retval = sprintf (buf, "%p", (char *) NULL); result |= retval != 5 || strcmp (buf, "(nil)") != 0; retval = swprintf (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), L"%p", (char *) NULL); result |= retval != 5 || wcscmp (wbuf, L"(nil)") != 0; return result; } volatile double qnanval; volatile long double lqnanval; /* A sNaN is only guaranteed to be representable in variables with static (or thread-local) storage duration. */ static volatile double snanval = __builtin_nans (""); static volatile double msnanval = -__builtin_nans (""); static volatile long double lsnanval = __builtin_nansl (""); static volatile long double lmsnanval = -__builtin_nansl (""); volatile double infval; volatile long double linfval; static int F (void) { char buf[80]; wchar_t wbuf[40]; int result = 0; qnanval = NAN;
//int g12 = __builtin_abs(-12); double g13 = __builtin_fabs(-12.); double g13_0 = __builtin_fabs(-0.); double g13_1 = __builtin_fabs(-__builtin_inf()); float g14 = __builtin_fabsf(-12.f); // GCC doesn't eat this one. //long double g15 = __builtin_fabsfl(-12.0L); float g16 = __builtin_copysign(1.0, -1.0); double g17 = __builtin_copysignf(1.0f, -1.0f); long double g18 = __builtin_copysignl(1.0L, -1.0L); char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nan(""))]; char classify_snan [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nans(""))]; char classify_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())]; char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())]; char classify_normal [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)]; char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)]; char classify_denorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)]; char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1, -1, -1e-308)]; char classify_zero [__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)]; char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)]; char isinf_sign_noninf1[__builtin_isinf_sign(-0.0) == 0 ? 1 : -1]; char isinf_sign_noninf2[__builtin_isinf_sign(1e307) == 0 ? 1 : -1]; char isinf_sign_noninf3[__builtin_isinf_sign(__builtin_nan("")) == 0 ? 1 : -1]; char isinf_sign_noninf4[__builtin_isinf_sign(-436.) == 0 ? 1 : -1]; char isinf_sign_inf [__builtin_isinf_sign(__builtin_inf()) == 1 ? 1 : -1]; char isinf_sign_neg_inf[__builtin_isinf_sign(-__builtin_inf()) == -1 ? 1 : -1];
License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ #include <math.h> #include <math_private.h> #include <stdbool.h> #include <stdio.h> struct test { double hi, lo1, lo2; }; static const struct test tests[] = { { __builtin_nan (""), 1, __builtin_nans ("") }, { -__builtin_nan (""), 1, __builtin_nans ("") }, { __builtin_nans (""), 1, __builtin_nan ("") }, { -__builtin_nans (""), 1, __builtin_nan ("") }, { __builtin_inf (), 0.0, -0.0 }, { -__builtin_inf (), 0.0, -0.0 }, { 1.5, 0.0, -0.0 }, }; static int do_test (void) { int result = 0; for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {