1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===--------------- addtf3_test.c - Test __addtf3 ------------------------===//
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 __addtf3 for the compiler_rt library.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "int_lib.h"
16 #include <stdio.h>
17
18 #if __LDBL_MANT_DIG__ == 113
19
20 #include "fp_test.h"
21
22 // Returns: a + b
23 COMPILER_RT_ABI long double __addtf3(long double a, long double b);
24
test__addtf3(long double a,long double b,uint64_t expectedHi,uint64_t expectedLo)25 int test__addtf3(long double a, long double b,
26 uint64_t expectedHi, uint64_t expectedLo)
27 {
28 long double x = __addtf3(a, b);
29 int ret = compareResultLD(x, expectedHi, expectedLo);
30
31 if (ret){
32 printf("error in test__addtf3(%.20Lf, %.20Lf) = %.20Lf, "
33 "expected %.20Lf\n", a, b, x,
34 fromRep128(expectedHi, expectedLo));
35 }
36
37 return ret;
38 }
39
40 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
41
42 #endif
43
main()44 int main()
45 {
46 #if __LDBL_MANT_DIG__ == 113
47 // qNaN + any = qNaN
48 if (test__addtf3(makeQNaN128(),
49 0x1.23456789abcdefp+5L,
50 UINT64_C(0x7fff800000000000),
51 UINT64_C(0x0)))
52 return 1;
53 // NaN + any = NaN
54 if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)),
55 0x1.23456789abcdefp+5L,
56 UINT64_C(0x7fff800000000000),
57 UINT64_C(0x0)))
58 return 1;
59 // inf + inf = inf
60 if (test__addtf3(makeInf128(),
61 makeInf128(),
62 UINT64_C(0x7fff000000000000),
63 UINT64_C(0x0)))
64 return 1;
65 // inf + any = inf
66 if (test__addtf3(makeInf128(),
67 0x1.2335653452436234723489432abcdefp+5L,
68 UINT64_C(0x7fff000000000000),
69 UINT64_C(0x0)))
70 return 1;
71 // any + any
72 if (test__addtf3(0x1.23456734245345543849abcdefp+5L,
73 0x1.edcba52449872455634654321fp-1L,
74 UINT64_C(0x40042afc95c8b579),
75 UINT64_C(0x61e58dd6c51eb77c)))
76 return 1;
77
78 #else
79 printf("skipped\n");
80
81 #endif
82 return 0;
83 }
84