1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===-- compiler_rt_logb_test.c - Test __compiler_rt_logb -----------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // This file checks __compiler_rt_logb from the compiler_rt library for
11 // conformance against libm.
13 //===----------------------------------------------------------------------===//
15 #define DOUBLE_PRECISION
20 int test__compiler_rt_logb(fp_t x
) {
21 fp_t crt_value
= __compiler_rt_logb(x
);
22 fp_t libm_value
= logb(x
);
23 // Compare actual rep, e.g. to avoid NaN != the same NaN
24 if (toRep(crt_value
) != toRep(libm_value
)) {
25 printf("error: in __compiler_rt_logb(%a [%lX]) = %a [%lX] != %a [%lX]\n",
26 x
, toRep(x
), crt_value
, toRep(crt_value
), libm_value
,
34 1.e
-6, -1.e
-6, NAN
, -NAN
, INFINITY
, -INFINITY
, -1,
35 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
38 #ifndef __GLIBC_PREREQ
39 #define __GLIBC_PREREQ(x, y) 0
43 // Do not the run the compiler-rt logb test case if using GLIBC version
44 // < 2.23. Older versions might not compute to the same value as the
46 #if __GLIBC_PREREQ(2, 23)
47 const unsigned N
= sizeof(cases
) / sizeof(cases
[0]);
49 for (i
= 0; i
< N
; ++i
) {
50 if (test__compiler_rt_logb(cases
[i
])) return 1;
53 // Test a moving 1 bit, especially to handle denormal values.
54 // Test the negation as well.
57 if (test__compiler_rt_logb(fromRep(x
))) return 1;
58 if (test__compiler_rt_logb(fromRep(signBit
^ x
))) return 1;
61 // Also try a couple moving ones
62 x
= signBit
| (signBit
>> 1) | (signBit
>> 2);
64 if (test__compiler_rt_logb(fromRep(x
))) return 1;
65 if (test__compiler_rt_logb(fromRep(signBit
^ x
))) return 1;