1 //===-- divdc3_test.c - Test __divdc3 -------------------------------------===//
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 __divdc3 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
19 // Returns: the quotient of (a + ib) / (c + id)
21 double _Complex
__divdc3(double __a
, double __b
, double __c
, double __d
);
23 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
26 classify(double _Complex x
)
30 if (isinf(creal(x
)) || isinf(cimag(x
)))
32 if (isnan(creal(x
)) && isnan(cimag(x
)))
49 int test__divdc3(double a
, double b
, double c
, double d
)
51 double _Complex r
= __divdc3(a
, b
, c
, d
);
52 // printf("test__divdc3(%f, %f, %f, %f) = %f + I%f\n",
53 // a, b, c, d, creal(r), cimag(r));
54 double _Complex dividend
;
55 double _Complex divisor
;
57 __real__ dividend
= a
;
58 __imag__ dividend
= b
;
62 switch (classify(dividend
))
65 switch (classify(divisor
))
68 if (classify(r
) != NaN
)
72 if (classify(r
) != zero
)
76 if (classify(r
) != zero
)
80 if (classify(r
) != NaN
)
84 if (classify(r
) != NaN
)
90 switch (classify(divisor
))
93 if (classify(r
) != inf
)
97 if (classify(r
) != non_zero
)
100 double _Complex z
= (a
* c
+ b
* d
) / (c
* c
+ d
* d
)
101 + (b
* c
- a
* d
) / (c
* c
+ d
* d
) * _Complex_I
;
102 if (cabs((r
-z
)/r
) > 1.e
-6)
107 if (classify(r
) != zero
)
111 if (classify(r
) != NaN
)
115 if (classify(r
) != NaN
)
121 switch (classify(divisor
))
124 if (classify(r
) != inf
)
128 if (classify(r
) != inf
)
132 if (classify(r
) != NaN
)
136 if (classify(r
) != NaN
)
140 if (classify(r
) != NaN
)
146 switch (classify(divisor
))
149 if (classify(r
) != NaN
)
153 if (classify(r
) != NaN
)
157 if (classify(r
) != NaN
)
161 if (classify(r
) != NaN
)
165 if (classify(r
) != NaN
)
171 switch (classify(divisor
))
174 if (classify(r
) != inf
)
178 if (classify(r
) != NaN
)
182 if (classify(r
) != NaN
)
186 if (classify(r
) != NaN
)
190 if (classify(r
) != NaN
)
235 {-INFINITY
, -INFINITY
},
244 {INFINITY
, -INFINITY
},
343 {-INFINITY
, INFINITY
},
358 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
360 for (i
= 0; i
< N
; ++i
)
362 for (j
= 0; j
< N
; ++j
)
364 if (test__divdc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))