1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===------------ getf2_test.c - Test __getf2------------------------------===//
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 __getf2 for the compiler_rt library.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include <stdio.h>
16 
17 #if __LP64__ && __LDBL_MANT_DIG__ == 113
18 
19 #include "fp_test.h"
20 
21 int __getf2(long double a, long double b);
22 
23 int test__getf2(long double a, long double b, enum EXPECTED_RESULT expected)
24 {
25     int x = __getf2(a, b);
26     int ret = compareResultCMP(x, expected);
27 
28     if (ret){
29         printf("error in test__getf2(%.20Lf, %.20Lf) = %d, "
30                "expected %s\n", a, b, x, expectedStr(expected));
31     }
32     return ret;
33 }
34 
35 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
36 
37 #endif
38 
39 int main()
40 {
41 #if __LP64__ && __LDBL_MANT_DIG__ == 113
42     // NaN
43     if (test__getf2(makeQNaN128(),
44                     0x1.234567890abcdef1234567890abcp+3L,
45                     LESS_0))
46         return 1;
47     // <
48     // exp
49     if (test__getf2(0x1.234567890abcdef1234567890abcp-3L,
50                     0x1.234567890abcdef1234567890abcp+3L,
51                     LESS_0))
52         return 1;
53     // mantissa
54     if (test__getf2(0x1.234567890abcdef1234567890abcp+3L,
55                     0x1.334567890abcdef1234567890abcp+3L,
56                     LESS_0))
57         return 1;
58     // sign
59     if (test__getf2(-0x1.234567890abcdef1234567890abcp+3L,
60                     0x1.234567890abcdef1234567890abcp+3L,
61                     LESS_0))
62         return 1;
63     // ==
64     if (test__getf2(0x1.234567890abcdef1234567890abcp+3L,
65                     0x1.234567890abcdef1234567890abcp+3L,
66                     GREATER_EQUAL_0))
67         return 1;
68     // >
69     // exp
70     if (test__getf2(0x1.234567890abcdef1234567890abcp+3L,
71                     0x1.234567890abcdef1234567890abcp-3L,
72                     GREATER_EQUAL_0))
73         return 1;
74     // mantissa
75     if (test__getf2(0x1.334567890abcdef1234567890abcp+3L,
76                     0x1.234567890abcdef1234567890abcp+3L,
77                     GREATER_EQUAL_0))
78         return 1;
79     // sign
80     if (test__getf2(0x1.234567890abcdef1234567890abcp+3L,
81                     -0x1.234567890abcdef1234567890abcp+3L,
82                     GREATER_EQUAL_0))
83         return 1;
84 
85 #else
86     printf("skipped\n");
87 
88 #endif
89     return 0;
90 }
91