1 // RUN: %clang_builtins %s %librt -o %t && %run %t
3 #define SINGLE_PRECISION
11 int test__compiler_rt_scalbnf(const char *mode
, fp_t x
, int y
) {
13 if (fpclassify(x
) == FP_SUBNORMAL
)
16 fp_t crt_value
= __compiler_rt_scalbnf(x
, y
);
17 fp_t libm_value
= scalbnf(x
, y
);
18 // Consider +/-0 unequal, but disregard the sign/payload of NaN.
19 if (toRep(crt_value
) != toRep(libm_value
) &&
20 !(crt_isnan(crt_value
) && crt_isnan(libm_value
))) {
21 printf("error: [%s] in __compiler_rt_scalbnf(%a [%X], %d) = %a [%X] "
23 mode
, x
, toRep(x
), y
, crt_value
, toRep(crt_value
),
24 libm_value
, toRep(libm_value
));
31 -NAN
, NAN
, -INFINITY
, INFINITY
, -0.0, 0.0, -1, 1, -2, 2,
32 FLT_TRUE_MIN
, FLT_TRUE_MIN
*7, FLT_MIN
, FLT_MAX
,
33 -1.001, 1.001, -1.002, 1.002, 1.e
-6, -1.e
-6,
36 0x1.0p
-127, // subnormal
37 0x1.0p
-128, // subnormal
40 int iterate_cases(const char *mode
) {
41 const unsigned N
= sizeof(cases
) / sizeof(cases
[0]);
43 for (i
= 0; i
< N
; ++i
) {
45 for (j
= -5; j
<= 5; ++j
) {
46 if (test__compiler_rt_scalbnf(mode
, cases
[i
], j
)) return 1;
48 if (test__compiler_rt_scalbnf(mode
, cases
[i
], -1000)) return 1;
49 if (test__compiler_rt_scalbnf(mode
, cases
[i
], 1000)) return 1;
50 if (test__compiler_rt_scalbnf(mode
, cases
[i
], INT_MIN
)) return 1;
51 if (test__compiler_rt_scalbnf(mode
, cases
[i
], INT_MAX
)) return 1;
57 if (iterate_cases("default")) return 1;
59 // Rounding mode tests on supported architectures. __compiler_rt_scalbnf
60 // should have the same rounding behavior as single-precision multiplication.
61 #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
62 defined(__i386__) || defined(__x86_64__)
63 // Skip these tests on Windows because the UCRT scalbnf function always behaves
64 // as if the default rounding mode is set (FE_TONEAREST).
65 // Also skip for newlib because although its scalbnf function does respect the
66 // rounding mode, where the tests trigger an underflow or overflow using a
67 // large exponent the result is rounded in the opposite direction to that which
68 // would be expected in the (FE_UPWARD) and (FE_DOWNWARD) modes.
69 # if !defined(_WIN32) && !defined(_NEWLIB_VERSION)
70 fesetround(FE_UPWARD
);
71 if (iterate_cases("FE_UPWARD")) return 1;
73 fesetround(FE_DOWNWARD
);
74 if (iterate_cases("FE_DOWNWARD")) return 1;
76 fesetround(FE_TOWARDZERO
);
77 if (iterate_cases("FE_TOWARDZERO")) return 1;
80 fesetround(FE_TONEAREST
);
81 if (iterate_cases("FE_TONEAREST")) return 1;