1 // RUN: %clang_builtins %s %librt -o %t && %run %t
3 #define DOUBLE_PRECISION
8 int test__compiler_rt_logb(fp_t x
) {
10 if (fpclassify(x
) == FP_SUBNORMAL
)
13 fp_t crt_value
= __compiler_rt_logb(x
);
14 fp_t libm_value
= logb(x
);
15 // Compare the values, considering all NaNs equivalent, as the spec doesn't
16 // specify the NaN signedness/payload.
17 if (crt_value
!= libm_value
&&
18 !(crt_isnan(crt_value
) && crt_isnan(libm_value
))) {
19 printf("error: in __compiler_rt_logb(%a [%lX]) = %a [%lX] != %a [%lX]\n",
20 x
, toRep(x
), crt_value
, toRep(crt_value
), libm_value
,
28 1.e
-6, -1.e
-6, NAN
, -NAN
, INFINITY
, -INFINITY
, -1,
29 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
32 #ifndef __GLIBC_PREREQ
33 #define __GLIBC_PREREQ(x, y) 0
37 // Do not the run the compiler-rt logb test case if using GLIBC version
38 // < 2.23. Older versions might not compute to the same value as the
40 #if __GLIBC_PREREQ(2, 23)
41 const unsigned N
= sizeof(cases
) / sizeof(cases
[0]);
43 for (i
= 0; i
< N
; ++i
) {
44 if (test__compiler_rt_logb(cases
[i
])) return 1;
47 // Test a moving 1 bit, especially to handle denormal values.
48 // Test the negation as well.
51 if (test__compiler_rt_logb(fromRep(x
))) return 1;
52 if (test__compiler_rt_logb(fromRep(signBit
^ x
))) return 1;
55 // Also try a couple moving ones
56 x
= signBit
| (signBit
>> 1) | (signBit
>> 2);
58 if (test__compiler_rt_logb(fromRep(x
))) return 1;
59 if (test__compiler_rt_logb(fromRep(signBit
^ x
))) return 1;