1 // RUN: %clang_builtins %s %librt -lm -o %t && %run %t
2 // REQUIRES: librt_has_divsc3
3 //===-- divsc3_test.c - Test __divsc3 -------------------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __divsc3 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
20 // REQUIRES: c99-complex
22 // Returns: the quotient of (a + ib) / (c + id)
24 COMPILER_RT_ABI
float _Complex
25 __divsc3(float __a
, float __b
, float __c
, float __d
);
27 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
30 classify(float _Complex x
)
34 if (isinf(crealf(x
)) || isinf(cimagf(x
)))
36 if (isnan(crealf(x
)) && isnan(cimagf(x
)))
53 int test__divsc3(float a
, float b
, float c
, float d
)
55 float _Complex r
= __divsc3(a
, b
, c
, d
);
56 // printf("test__divsc3(%f, %f, %f, %f) = %f + I%f\n",
57 // a, b, c, d, crealf(r), cimagf(r));
58 float _Complex dividend
;
59 float _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 float _Complex z
= (a
* c
+ b
* d
) / (c
* c
+ d
* d
)
105 + (b
* c
- a
* d
) / (c
* c
+ d
* d
) * _Complex_I
;
106 if (cabsf((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
},
362 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
364 for (i
= 0; i
< N
; ++i
)
366 for (j
= 0; j
< N
; ++j
)
368 if (test__divsc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))