1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===-- compiler_rt_logbf_test.c - Test __compiler_rt_logbf ---------------===//
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_logbf from the compiler_rt library for
11 // conformance against libm.
13 //===----------------------------------------------------------------------===//
15 #define SINGLE_PRECISION
21 int test__compiler_rt_logbf(fp_t x
) {
22 fp_t crt_value
= __compiler_rt_logbf(x
);
23 fp_t libm_value
= logbf(x
);
24 // `!=` operator on fp_t returns false for NaNs so also check if operands are
25 // both NaN. We don't do `toRepr(crt_value) != toRepr(libm_value)` because
26 // that treats different representations of NaN as not equivalent.
27 if (crt_value
!= libm_value
&&
28 !(crt_isnan(crt_value
) && crt_isnan(libm_value
))) {
29 printf("error: in __compiler_rt_logb(%a [%X]) = %a [%X] != %a [%X]\n", x
,
30 toRep(x
), crt_value
, toRep(crt_value
), libm_value
,
38 1.e
-6, -1.e
-6, NAN
, -NAN
, INFINITY
, -INFINITY
, -1,
39 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
43 const unsigned N
= sizeof(cases
) / sizeof(cases
[0]);
45 for (i
= 0; i
< N
; ++i
) {
46 if (test__compiler_rt_logbf(cases
[i
])) return 1;
49 // Test a moving 1 bit, especially to handle denormal values.
50 // Test the negation as well.
53 if (test__compiler_rt_logbf(fromRep(x
))) return 1;
54 if (test__compiler_rt_logbf(fromRep(signBit
^ x
))) return 1;
57 // Also try a couple moving ones
58 x
= signBit
| (signBit
>> 1) | (signBit
>> 2);
60 if (test__compiler_rt_logbf(fromRep(x
))) return 1;
61 if (test__compiler_rt_logbf(fromRep(signBit
^ x
))) return 1;