1 // RUN: %clang_builtins %s %librt -lm -o %t && %run %t
2 // REQUIRES: librt_has_divsc3
3 // REQUIRES: c99-complex
11 // Returns: the quotient of (a + ib) / (c + id)
13 COMPILER_RT_ABI
float _Complex
14 __divsc3(float __a
, float __b
, float __c
, float __d
);
16 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
19 classify(float _Complex x
)
23 if (isinf(crealf(x
)) || isinf(cimagf(x
)))
25 if (isnan(crealf(x
)) && isnan(cimagf(x
)))
42 int test__divsc3(float a
, float b
, float c
, float d
)
44 float _Complex r
= __divsc3(a
, b
, c
, d
);
45 // printf("test__divsc3(%f, %f, %f, %f) = %f + I%f\n",
46 // a, b, c, d, crealf(r), cimagf(r));
47 float _Complex dividend
;
48 float _Complex divisor
;
50 __real__ dividend
= a
;
51 __imag__ dividend
= b
;
55 switch (classify(dividend
))
58 switch (classify(divisor
))
61 if (classify(r
) != NaN
)
65 if (classify(r
) != zero
)
69 if (classify(r
) != zero
)
73 if (classify(r
) != NaN
)
77 if (classify(r
) != NaN
)
83 switch (classify(divisor
))
86 if (classify(r
) != inf
)
90 if (classify(r
) != non_zero
)
93 float _Complex z
= (a
* c
+ b
* d
) / (c
* c
+ d
* d
)
94 + (b
* c
- a
* d
) / (c
* c
+ d
* d
) * _Complex_I
;
95 if (cabsf((r
-z
)/r
) > 1.e
-6)
100 if (classify(r
) != zero
)
104 if (classify(r
) != NaN
)
108 if (classify(r
) != NaN
)
114 switch (classify(divisor
))
117 if (classify(r
) != inf
)
121 if (classify(r
) != inf
)
125 if (classify(r
) != NaN
)
129 if (classify(r
) != NaN
)
133 if (classify(r
) != NaN
)
139 switch (classify(divisor
))
142 if (classify(r
) != NaN
)
146 if (classify(r
) != NaN
)
150 if (classify(r
) != NaN
)
154 if (classify(r
) != NaN
)
158 if (classify(r
) != NaN
)
164 switch (classify(divisor
))
167 if (classify(r
) != inf
)
171 if (classify(r
) != NaN
)
175 if (classify(r
) != NaN
)
179 if (classify(r
) != NaN
)
183 if (classify(r
) != NaN
)
228 {-INFINITY
, -INFINITY
},
237 {INFINITY
, -INFINITY
},
336 {-INFINITY
, INFINITY
},
351 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
353 for (i
= 0; i
< N
; ++i
)
355 for (j
= 0; j
< N
; ++j
)
357 if (test__divsc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))