1 //===-- muldc3_test.c - Test __muldc3 -------------------------------------===//
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 __muldc3 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
19 // Returns: the product of a + ib and c + id
21 double _Complex
__muldc3(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__muldc3(double a
, double b
, double c
, double d
)
51 double _Complex r
= __muldc3(a
, b
, c
, d
);
52 // printf("test__muldc3(%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
) != zero
)
72 if (classify(r
) != zero
)
76 if (classify(r
) != NaN
)
80 if (classify(r
) != NaN
)
84 if (classify(r
) != NaN
)
90 switch (classify(divisor
))
93 if (classify(r
) != zero
)
97 if (classify(r
) != non_zero
)
99 if (r
!= a
* c
- b
* d
+ _Complex_I
*(a
* d
+ b
* c
))
103 if (classify(r
) != inf
)
107 if (classify(r
) != NaN
)
111 if (classify(r
) != NaN
)
117 switch (classify(divisor
))
120 if (classify(r
) != NaN
)
124 if (classify(r
) != inf
)
128 if (classify(r
) != inf
)
132 if (classify(r
) != NaN
)
136 if (classify(r
) != inf
)
142 switch (classify(divisor
))
145 if (classify(r
) != NaN
)
149 if (classify(r
) != NaN
)
153 if (classify(r
) != NaN
)
157 if (classify(r
) != NaN
)
161 if (classify(r
) != NaN
)
167 switch (classify(divisor
))
170 if (classify(r
) != NaN
)
174 if (classify(r
) != NaN
)
178 if (classify(r
) != inf
)
182 if (classify(r
) != NaN
)
186 if (classify(r
) != NaN
)
231 {-INFINITY
, -INFINITY
},
240 {INFINITY
, -INFINITY
},
339 {-INFINITY
, INFINITY
},
354 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
356 for (i
= 0; i
< N
; ++i
)
358 for (j
= 0; j
< N
; ++j
)
360 if (test__muldc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))