1 //===-- divtc3_test.c - Test __divtc3 -------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __divtc3 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
21 // Returns: the quotient of (a + ib) / (c + id)
24 __divtc3(long double __a
, long double __b
, long double __c
, long double __d
);
26 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
29 classify(long double _Complex x
)
33 if (isinf(creall(x
)) || isinf(cimagl(x
)))
35 if (isnan(creall(x
)) && isnan(cimagl(x
)))
52 int test__divtc3(long double a
, long double b
, long double c
, long double d
)
54 long double _Complex r
= __divtc3(a
, b
, c
, d
);
55 // printf("test__divtc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
56 // a, b, c, d, creall(r), cimagl(r));
58 long double _Complex dividend
;
59 long double _Complex divisor
;
61 __real__ dividend
= a
;
62 __imag__ dividend
= b
;
66 switch (classify(dividend
))
69 switch (classify(divisor
))
72 if (classify(r
) != NaN
)
76 if (classify(r
) != zero
)
80 if (classify(r
) != zero
)
84 if (classify(r
) != NaN
)
88 if (classify(r
) != NaN
)
94 switch (classify(divisor
))
97 if (classify(r
) != inf
)
101 if (classify(r
) != non_zero
)
104 long double _Complex z
= (a
* c
+ b
* d
) / (c
* c
+ d
* d
)
105 + (b
* c
- a
* d
) / (c
* c
+ d
* d
) * _Complex_I
;
106 if (cabs((r
- z
)/r
) > 1.e
-6)
111 if (classify(r
) != zero
)
115 if (classify(r
) != NaN
)
119 if (classify(r
) != NaN
)
125 switch (classify(divisor
))
128 if (classify(r
) != inf
)
132 if (classify(r
) != inf
)
136 if (classify(r
) != NaN
)
140 if (classify(r
) != NaN
)
144 if (classify(r
) != NaN
)
150 switch (classify(divisor
))
153 if (classify(r
) != NaN
)
157 if (classify(r
) != NaN
)
161 if (classify(r
) != NaN
)
165 if (classify(r
) != NaN
)
169 if (classify(r
) != NaN
)
175 switch (classify(divisor
))
178 if (classify(r
) != inf
)
182 if (classify(r
) != NaN
)
186 if (classify(r
) != NaN
)
190 if (classify(r
) != NaN
)
194 if (classify(r
) != NaN
)
239 {-INFINITY
, -INFINITY
},
248 {INFINITY
, -INFINITY
},
347 {-INFINITY
, INFINITY
},
365 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
367 for (i
= 0; i
< N
; ++i
)
369 for (j
= 0; j
< N
; ++j
)
371 if (test__divtc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))
376 // printf("No errors found.\n");