[clang-format] Write in text mode with LF in dump_format_[help|style].py
[llvm-project.git] / libcxx / test / std / numerics / complex.number / complex.transcendentals / tan.pass.cpp
blob5c1f61ef644d3a1d4ec59b1f998711ce1872fd18
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <complex>
11 // template<class T>
12 // complex<T>
13 // tan(const complex<T>& x);
15 #include <complex>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "../cases.h"
21 template <class T>
22 void
23 test(const std::complex<T>& c, std::complex<T> x)
25 assert(tan(c) == x);
28 template <class T>
29 void
30 test()
32 test(std::complex<T>(0, 0), std::complex<T>(0, 0));
33 test(std::complex<T>(10000, -10000), std::complex<T>(0, -1));
36 void test_edges()
38 const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
39 for (unsigned i = 0; i < N; ++i)
41 std::complex<double> r = tan(testcases[i]);
42 std::complex<double> t1(-imag(testcases[i]), real(testcases[i]));
43 std::complex<double> t2 = tanh(t1);
44 std::complex<double> z(imag(t2), -real(t2));
45 if (std::isnan(real(r)))
46 assert(std::isnan(real(z)));
47 else
49 assert(real(r) == real(z));
50 assert(std::signbit(real(r)) == std::signbit(real(z)));
52 if (std::isnan(imag(r)))
53 assert(std::isnan(imag(z)));
54 else
56 assert(imag(r) == imag(z));
57 assert(std::signbit(imag(r)) == std::signbit(imag(z)));
62 int main(int, char**)
64 test<float>();
65 test<double>();
66 test<long double>();
67 test_edges();
69 return 0;