1 // RUN: %clang_builtins %s %librt -lm -o %t && %run %t
2 // REQUIRES: librt_has_divtc3
4 // 32-bit: Bug 42493, 64-bit: Bug 42496
7 //===-- divtc3_test.c - Test __divtc3 -------------------------------------===//
9 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10 // See https://llvm.org/LICENSE.txt for license information.
11 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13 //===----------------------------------------------------------------------===//
15 // This file tests __divtc3 for the compiler_rt library.
17 //===----------------------------------------------------------------------===//
25 // REQUIRES: c99-complex
27 // Returns: the quotient of (a + ib) / (c + id)
29 COMPILER_RT_ABI
long double _Complex
30 __divtc3(long double __a
, long double __b
, long double __c
, long double __d
);
32 enum {zero
, non_zero
, inf
, NaN
, non_zero_nan
};
35 classify(long double _Complex x
)
39 if (isinf(creall(x
)) || isinf(cimagl(x
)))
41 if (isnan(creall(x
)) && isnan(cimagl(x
)))
58 int test__divtc3(long double a
, long double b
, long double c
, long double d
)
60 long double _Complex r
= __divtc3(a
, b
, c
, d
);
61 // printf("test__divtc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
62 // a, b, c, d, creall(r), cimagl(r));
64 long double _Complex dividend
;
65 long double _Complex divisor
;
67 __real__ dividend
= a
;
68 __imag__ dividend
= b
;
72 switch (classify(dividend
))
75 switch (classify(divisor
))
78 if (classify(r
) != NaN
)
82 if (classify(r
) != zero
)
86 if (classify(r
) != zero
)
90 if (classify(r
) != NaN
)
94 if (classify(r
) != NaN
)
100 switch (classify(divisor
))
103 if (classify(r
) != inf
)
107 if (classify(r
) != non_zero
)
110 long double _Complex z
= (a
* c
+ b
* d
) / (c
* c
+ d
* d
)
111 + (b
* c
- a
* d
) / (c
* c
+ d
* d
) * _Complex_I
;
112 if (cabsl((r
- z
)/r
) > 1.e
-6)
117 if (classify(r
) != zero
)
121 if (classify(r
) != NaN
)
125 if (classify(r
) != NaN
)
131 switch (classify(divisor
))
134 if (classify(r
) != inf
)
138 if (classify(r
) != inf
)
142 if (classify(r
) != NaN
)
146 if (classify(r
) != NaN
)
150 if (classify(r
) != NaN
)
156 switch (classify(divisor
))
159 if (classify(r
) != NaN
)
163 if (classify(r
) != NaN
)
167 if (classify(r
) != NaN
)
171 if (classify(r
) != NaN
)
175 if (classify(r
) != NaN
)
181 switch (classify(divisor
))
184 if (classify(r
) != inf
)
188 if (classify(r
) != NaN
)
192 if (classify(r
) != NaN
)
196 if (classify(r
) != NaN
)
200 if (classify(r
) != NaN
)
245 {-INFINITY
, -INFINITY
},
254 {INFINITY
, -INFINITY
},
353 {-INFINITY
, INFINITY
},
368 const unsigned N
= sizeof(x
) / sizeof(x
[0]);
370 for (i
= 0; i
< N
; ++i
)
372 for (j
= 0; j
< N
; ++j
)
374 if (test__divtc3(x
[i
][0], x
[i
][1], x
[j
][0], x
[j
][1]))
379 // printf("No errors found.\n");