1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_subtf3
7 #if __LDBL_MANT_DIG__ == 113
13 COMPILER_RT_ABI
long double __subtf3(long double a
, long double b
);
15 int test__subtf3(long double a
, long double b
,
16 uint64_t expectedHi
, uint64_t expectedLo
)
18 long double x
= __subtf3(a
, b
);
19 int ret
= compareResultF128(x
, expectedHi
, expectedLo
);
22 printf("error in test__subtf3(%.20Lf, %.20Lf) = %.20Lf, "
23 "expected %.20Lf\n", a
, b
, x
,
24 fromRep128(expectedHi
, expectedLo
));
29 char assumption_1
[sizeof(long double) * CHAR_BIT
== 128] = {0};
35 #if __LDBL_MANT_DIG__ == 113
37 if (test__subtf3(makeQNaN128(),
38 0x1.23456789abcdefp
+5L,
39 UINT64_C(0x7fff800000000000),
43 if (test__subtf3(makeNaN128(UINT64_C(0x800030000000)),
44 0x1.23456789abcdefp
+5L,
45 UINT64_C(0x7fff800000000000),
49 if (test__subtf3(makeInf128(),
50 0x1.23456789abcdefp
+5L,
51 UINT64_C(0x7fff000000000000),
55 if (test__subtf3(0x1.234567829a3bcdef5678ade36734p
+5L,
56 0x1.ee9d7c52354a6936ab8d7654321fp
-1L,
57 UINT64_C(0x40041b8af1915166),
58 UINT64_C(0xa44a7bca780a166c)))
61 #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
62 defined(i386) || defined(__x86_64__) || (defined(__loongarch__) && \
63 __loongarch_frlen != 0)
64 // Rounding mode tests on supported architectures
65 const long double m
= 1234.02L, n
= 0.01L;
67 fesetround(FE_UPWARD
);
68 if (test__subtf3(m
, n
,
69 UINT64_C(0x40093480a3d70a3d),
70 UINT64_C(0x70a3d70a3d70a3d7)))
73 fesetround(FE_DOWNWARD
);
74 if (test__subtf3(m
, n
,
75 UINT64_C(0x40093480a3d70a3d),
76 UINT64_C(0x70a3d70a3d70a3d6)))
79 fesetround(FE_TOWARDZERO
);
80 if (test__subtf3(m
, n
,
81 UINT64_C(0x40093480a3d70a3d),
82 UINT64_C(0x70a3d70a3d70a3d6)))
85 fesetround(FE_TONEAREST
);
86 if (test__subtf3(m
, n
,
87 UINT64_C(0x40093480a3d70a3d),
88 UINT64_C(0x70a3d70a3d70a3d7)))