1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_subtf3
3 //===--------------- subtf3_test.c - Test __subtf3 ------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __subtf3 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
18 #if __LDBL_MANT_DIG__ == 113
24 COMPILER_RT_ABI
long double __subtf3(long double a
, long double b
);
26 int test__subtf3(long double a
, long double b
,
27 uint64_t expectedHi
, uint64_t expectedLo
)
29 long double x
= __subtf3(a
, b
);
30 int ret
= compareResultLD(x
, expectedHi
, expectedLo
);
33 printf("error in test__subtf3(%.20Lf, %.20Lf) = %.20Lf, "
34 "expected %.20Lf\n", a
, b
, x
,
35 fromRep128(expectedHi
, expectedLo
));
40 char assumption_1
[sizeof(long double) * CHAR_BIT
== 128] = {0};
46 #if __LDBL_MANT_DIG__ == 113
48 if (test__subtf3(makeQNaN128(),
49 0x1.23456789abcdefp
+5L,
50 UINT64_C(0x7fff800000000000),
54 if (test__subtf3(makeNaN128(UINT64_C(0x800030000000)),
55 0x1.23456789abcdefp
+5L,
56 UINT64_C(0x7fff800000000000),
60 if (test__subtf3(makeInf128(),
61 0x1.23456789abcdefp
+5L,
62 UINT64_C(0x7fff000000000000),
66 if (test__subtf3(0x1.234567829a3bcdef5678ade36734p
+5L,
67 0x1.ee9d7c52354a6936ab8d7654321fp
-1L,
68 UINT64_C(0x40041b8af1915166),
69 UINT64_C(0xa44a7bca780a166c)))
72 #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
73 defined(i386) || defined(__x86_64__)
74 // Rounding mode tests on supported architectures
75 const long double m
= 1234.02L, n
= 0.01L;
77 fesetround(FE_UPWARD
);
78 if (test__subtf3(m
, n
,
79 UINT64_C(0x40093480a3d70a3d),
80 UINT64_C(0x70a3d70a3d70a3d7)))
83 fesetround(FE_DOWNWARD
);
84 if (test__subtf3(m
, n
,
85 UINT64_C(0x40093480a3d70a3d),
86 UINT64_C(0x70a3d70a3d70a3d6)))
89 fesetround(FE_TOWARDZERO
);
90 if (test__subtf3(m
, n
,
91 UINT64_C(0x40093480a3d70a3d),
92 UINT64_C(0x70a3d70a3d70a3d6)))
95 fesetround(FE_TONEAREST
);
96 if (test__subtf3(m
, n
,
97 UINT64_C(0x40093480a3d70a3d),
98 UINT64_C(0x70a3d70a3d70a3d7)))