1 // RUN: %clang_builtins %s %librt -o %t && %run %t
3 #define SINGLE_PRECISION
9 int test__compiler_rt_logbf(fp_t x
) {
11 if (fpclassify(x
) == FP_SUBNORMAL
)
14 fp_t crt_value
= __compiler_rt_logbf(x
);
15 fp_t libm_value
= logbf(x
);
16 // `!=` operator on fp_t returns false for NaNs so also check if operands are
17 // both NaN. We don't do `toRepr(crt_value) != toRepr(libm_value)` because
18 // that treats different representations of NaN as not equivalent.
19 if (crt_value
!= libm_value
&&
20 !(crt_isnan(crt_value
) && crt_isnan(libm_value
))) {
21 printf("error: in __compiler_rt_logb(%a [%X]) = %a [%X] != %a [%X]\n", x
,
22 toRep(x
), crt_value
, toRep(crt_value
), libm_value
,
30 1.e
-6, -1.e
-6, NAN
, -NAN
, INFINITY
, -INFINITY
, -1,
31 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
35 const unsigned N
= sizeof(cases
) / sizeof(cases
[0]);
37 for (i
= 0; i
< N
; ++i
) {
38 if (test__compiler_rt_logbf(cases
[i
])) return 1;
41 // Test a moving 1 bit, especially to handle denormal values.
42 // Test the negation as well.
45 if (test__compiler_rt_logbf(fromRep(x
))) return 1;
46 if (test__compiler_rt_logbf(fromRep(signBit
^ x
))) return 1;
49 // Also try a couple moving ones
50 x
= signBit
| (signBit
>> 1) | (signBit
>> 2);
52 if (test__compiler_rt_logbf(fromRep(x
))) return 1;
53 if (test__compiler_rt_logbf(fromRep(signBit
^ x
))) return 1;