1 // RUN: %clang_builtins %s -ffp-contract=off %librt -lm -o %t && %run %t
2 // REQUIRES: librt_has_muldc3
3 // REQUIRES: c99-complex
11 // Returns: the product of a + ib and c + id
13 COMPILER_RT_ABI
double _Complex
14 __muldc3(double __a
, double __b
, double __c
, double __d
);
16 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
19 classify(double _Complex x
)
23 if (isinf(creal(x
)) || isinf(cimag(x
)))
25 if (isnan(creal(x
)) && isnan(cimag(x
)))
42 int test__muldc3(double a
, double b
, double c
, double d
)
44 double _Complex r
= __muldc3(a
, b
, c
, d
);
45 // printf("test__muldc3(%f, %f, %f, %f) = %f + I%f\n",
46 // a, b, c, d, creal(r), cimag(r));
47 double _Complex dividend
;
48 double _Complex divisor
;
50 __real__ dividend
= a
;
51 __imag__ dividend
= b
;
55 switch (classify(dividend
))
58 switch (classify(divisor
))
61 if (classify(r
) != zero
)
65 if (classify(r
) != zero
)
69 if (classify(r
) != NaN
)
73 if (classify(r
) != NaN
)
77 if (classify(r
) != NaN
)
83 switch (classify(divisor
))
86 if (classify(r
) != zero
)
90 if (classify(r
) != non_zero
)
92 if (r
!= a
* c
- b
* d
+ _Complex_I
*(a
* d
+ b
* c
))
96 if (classify(r
) != inf
)
100 if (classify(r
) != NaN
)
104 if (classify(r
) != NaN
)
110 switch (classify(divisor
))
113 if (classify(r
) != NaN
)
117 if (classify(r
) != inf
)
121 if (classify(r
) != inf
)
125 if (classify(r
) != NaN
)
129 if (classify(r
) != inf
)
135 switch (classify(divisor
))
138 if (classify(r
) != NaN
)
142 if (classify(r
) != NaN
)
146 if (classify(r
) != NaN
)
150 if (classify(r
) != NaN
)
154 if (classify(r
) != NaN
)
160 switch (classify(divisor
))
163 if (classify(r
) != NaN
)
167 if (classify(r
) != NaN
)
171 if (classify(r
) != inf
)
175 if (classify(r
) != NaN
)
179 if (classify(r
) != NaN
)
224 {-INFINITY
, -INFINITY
},
233 {INFINITY
, -INFINITY
},
332 {-INFINITY
, INFINITY
},
347 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
349 for (i
= 0; i
< N
; ++i
)
351 for (j
= 0; j
< N
; ++j
)
353 if (test__muldc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))