1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===-- compiler_rt_logb_test.c - Test __compiler_rt_logb -----------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // This file checks __compiler_rt_logb from the compiler_rt library for
12 // conformance against libm.
14 //===----------------------------------------------------------------------===//
16 #define DOUBLE_PRECISION
21 int test__compiler_rt_logb(fp_t x) {
22 fp_t crt_value = __compiler_rt_logb(x);
23 fp_t libm_value = logb(x);
24 // Compare actual rep, e.g. to avoid NaN != the same NaN
25 if (toRep(crt_value) != toRep(libm_value)) {
26 printf("error: in __compiler_rt_logb(%a [%lX]) = %a [%lX] != %a [%lX]\n",
27 x, toRep(x), crt_value, toRep(crt_value), libm_value,
35 1.e-6, -1.e-6, NAN, -NAN, INFINITY, -INFINITY, -1,
36 -0.0, 0.0, 1, -2, 2, -0.5, 0.5,
40 const unsigned N = sizeof(cases) / sizeof(cases[0]);
42 for (i = 0; i < N; ++i) {
43 if (test__compiler_rt_logb(cases[i])) return 1;
46 // Test a moving 1 bit, especially to handle denormal values.
47 // Test the negation as well.
50 if (test__compiler_rt_logb(fromRep(x))) return 1;
51 if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1;
54 // Also try a couple moving ones
55 x = signBit | (signBit >> 1) | (signBit >> 2);
57 if (test__compiler_rt_logb(fromRep(x))) return 1;
58 if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1;