1//===--------------- divtf3_test.c - Test __divtf3 ------------------------===//
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 __divtf3 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
21long double __divtf3(long double a, long double b);
22
23int test__divtf3(long double a, long double b,
24                 uint64_t expectedHi, uint64_t expectedLo)
25{
26    long double x = __divtf3(a, b);
27    int ret = compareResultLD(x, expectedHi, expectedLo);
28
29    if (ret){
30        printf("error in test__divtf3(%.20Lf, %.20Lf) = %.20Lf, "
31               "expected %.20Lf\n", a, b, x,
32               fromRep128(expectedHi, expectedLo));
33    }
34    return ret;
35}
36
37char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
38
39#endif
40
41int main()
42{
43#if __LDBL_MANT_DIG__ == 113
44    // qNaN / any = qNaN
45    if (test__divtf3(makeQNaN128(),
46                     0x1.23456789abcdefp+5L,
47                     UINT64_C(0x7fff800000000000),
48                     UINT64_C(0x0)))
49        return 1;
50    // NaN / any = NaN
51    if (test__divtf3(makeNaN128(UINT64_C(0x800030000000)),
52                     0x1.23456789abcdefp+5L,
53                     UINT64_C(0x7fff800000000000),
54                     UINT64_C(0x0)))
55        return 1;
56    // inf / any = inf
57    if (test__divtf3(makeInf128(),
58                     0x1.23456789abcdefp+5L,
59                     UINT64_C(0x7fff000000000000),
60                     UINT64_C(0x0)))
61        return 1;
62    // any / any
63    if (test__divtf3(0x1.a23b45362464523375893ab4cdefp+5L,
64                     0x1.eedcbaba3a94546558237654321fp-1L,
65                     UINT64_C(0x4004b0b72924d407),
66                     UINT64_C(0x0717e84356c6eba2)))
67        return 1;
68    if (test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50L,
69                     0x1.ed2c3ba15935332532287654321fp-9L,
70                     UINT64_C(0x3fd5b2af3f828c9b),
71                     UINT64_C(0x40e51f64cde8b1f2)))
72        return 15;
73    if (test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456L,
74                     0x1.edacbba9874f765463544dd3621fp+6400L,
75                     UINT64_C(0x28c62e15dc464466),
76                     UINT64_C(0xb5a07586348557ac)))
77        return 1;
78    if (test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234L,
79                     0x1.eddcdba39f3c8b7a36564354321fp-4455L,
80                     UINT64_C(0x507b38442b539266),
81                     UINT64_C(0x22ce0f1d024e1252)))
82        return 1;
83    if (test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234L,
84                     0x1.edcba987d6bb3aa467754354321fp-4055L,
85                     UINT64_C(0x50bf2e02f0798d36),
86                     UINT64_C(0x5e6fcb6b60044078)))
87        return 1;
88
89#else
90    printf("skipped\n");
91
92#endif
93    return 0;
94}
95