1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===--------------- subtf3_test.c - Test __subtf3 ------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This file tests __subtf3 for the compiler_rt library.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include <stdio.h>
16 
17 #if __LDBL_MANT_DIG__ == 113
18 
19 #include "int_lib.h"
20 #include "fp_test.h"
21 
22 // Returns: a - b
23 COMPILER_RT_ABI long double __subtf3(long double a, long double b);
24 
test__subtf3(long double a,long double b,uint64_t expectedHi,uint64_t expectedLo)25 int test__subtf3(long double a, long double b,
26                  uint64_t expectedHi, uint64_t expectedLo)
27 {
28     long double x = __subtf3(a, b);
29     int ret = compareResultLD(x, expectedHi, expectedLo);
30 
31     if (ret){
32         printf("error in test__subtf3(%.20Lf, %.20Lf) = %.20Lf, "
33                "expected %.20Lf\n", a, b, x,
34                fromRep128(expectedHi, expectedLo));
35     }
36     return ret;
37 }
38 
39 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
40 
41 #endif
42 
main()43 int main()
44 {
45 #if __LDBL_MANT_DIG__ == 113
46     // qNaN - any = qNaN
47     if (test__subtf3(makeQNaN128(),
48                      0x1.23456789abcdefp+5L,
49                      UINT64_C(0x7fff800000000000),
50                      UINT64_C(0x0)))
51         return 1;
52     // NaN - any = NaN
53     if (test__subtf3(makeNaN128(UINT64_C(0x800030000000)),
54                      0x1.23456789abcdefp+5L,
55                      UINT64_C(0x7fff800000000000),
56                      UINT64_C(0x0)))
57         return 1;
58     // inf - any = inf
59     if (test__subtf3(makeInf128(),
60                      0x1.23456789abcdefp+5L,
61                      UINT64_C(0x7fff000000000000),
62                      UINT64_C(0x0)))
63         return 1;
64     // any - any
65     if (test__subtf3(0x1.234567829a3bcdef5678ade36734p+5L,
66                      0x1.ee9d7c52354a6936ab8d7654321fp-1L,
67                      UINT64_C(0x40041b8af1915166),
68                      UINT64_C(0xa44a7bca780a166c)))
69         return 1;
70 
71 #else
72     printf("skipped\n");
73 
74 #endif
75     return 0;
76 }
77