1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // polar(const T& rho, const T& theta = T()); // changed from '0' by LWG#2870
18 #include "test_macros.h"
23 test(const T
& rho
, std::complex<T
> x
)
25 assert(std::polar(rho
) == x
);
30 test(const T
& rho
, const T
& theta
, std::complex<T
> x
)
32 assert(std::polar(rho
, theta
) == x
);
39 test(T(0), std::complex<T
>(0, 0));
40 test(T(1), std::complex<T
>(1, 0));
41 test(T(100), std::complex<T
>(100, 0));
42 test(T(0), T(0), std::complex<T
>(0, 0));
43 test(T(1), T(0), std::complex<T
>(1, 0));
44 test(T(100), T(0), std::complex<T
>(100, 0));
49 const unsigned N
= sizeof(testcases
) / sizeof(testcases
[0]);
50 for (unsigned i
= 0; i
< N
; ++i
)
52 double r
= real(testcases
[i
]);
53 double theta
= imag(testcases
[i
]);
54 std::complex<double> z
= std::polar(r
, theta
);
58 if (std::signbit(r
) || classify(theta
) == inf
|| classify(theta
) == NaN
)
61 assert(c
== NaN
|| c
== non_zero_nan
);
65 assert(z
== std::complex<double>());
69 if (std::signbit(r
) || classify(theta
) == inf
|| classify(theta
) == NaN
)
72 assert(c
== NaN
|| c
== non_zero_nan
);
76 is_about(std::abs(z
), r
);
83 assert(c
== NaN
|| c
== non_zero_nan
);
87 assert(classify(z
) == inf
);
88 if (classify(theta
) != NaN
&& classify(theta
) != inf
)
90 assert(classify(real(z
)) != NaN
);
91 assert(classify(imag(z
)) != NaN
);
99 assert(c
== NaN
|| c
== non_zero_nan
);
106 int main(int, char**)