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