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//===----------------------------------------------------------------------===//
8
9// <complex>
10
11// template<class T>
12// complex<T>
13// cosh(const complex<T>& x);
14
15#include <complex>
16#include <cassert>
17
18#include "test_macros.h"
19#include "../cases.h"
20
21template <class T>
22void
23test(const std::complex<T>& c, std::complex<T> x)
24{
25 assert(cosh(c) == x);
26}
27
28template <class T>
29void
30test()
31{
32 test(std::complex<T>(0, 0), std::complex<T>(1, 0));
33}
34
35void test_edges()
36{
37 const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
38 for (unsigned i = 0; i < N; ++i)
39 {
40 std::complex<double> r = cosh(testcases[i]);
41 if (testcases[i].real() == 0 && testcases[i].imag() == 0)
42 {
43 assert(r.real() == 1);
44 assert(r.imag() == 0);
45 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
46 }
47 else if (testcases[i].real() == 0 && std::isinf(testcases[i].imag()))
48 {
49 assert(std::isnan(r.real()));
50 assert(r.imag() == 0);
51 }
52 else if (testcases[i].real() == 0 && std::isnan(testcases[i].imag()))
53 {
54 assert(std::isnan(r.real()));
55 assert(r.imag() == 0);
56 }
57 else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
58 {
59 assert(std::isnan(r.real()));
60 assert(std::isnan(r.imag()));
61 }
62 else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag()))
63 {
64 assert(std::isnan(r.real()));
65 assert(std::isnan(r.imag()));
66 }
67 else if (std::isinf(testcases[i].real()) && testcases[i].imag() == 0)
68 {
69 assert(std::isinf(r.real()));
70 assert(!std::signbit(r.real()));
71 assert(r.imag() == 0);
72 assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
73 }
74 else if (std::isinf(testcases[i].real()) && std::isfinite(testcases[i].imag()))
75 {
76 assert(std::isinf(r.real()));
77 assert(std::signbit(r.real()) == std::signbit(cos(testcases[i].imag())));
78 assert(std::isinf(r.imag()));
79 assert(std::signbit(r.imag()) == std::signbit(testcases[i].real() * sin(testcases[i].imag())));
80 }
81 else if (std::isinf(testcases[i].real()) && std::isinf(testcases[i].imag()))
82 {
83 assert(std::isinf(r.real()));
84 assert(std::isnan(r.imag()));
85 }
86 else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
87 {
88 assert(std::isinf(r.real()));
89 assert(r.real() > 0);
90 assert(std::isnan(r.imag()));
91 }
92 else if (std::isnan(testcases[i].real()) && testcases[i].imag() == 0)
93 {
94 assert(std::isnan(r.real()));
95 assert(r.imag() == 0);
96 }
97 else if (std::isnan(testcases[i].real()) && std::isfinite(testcases[i].imag()))
98 {
99 assert(std::isnan(r.real()));
100 assert(std::isnan(r.imag()));
101 }
102 else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag()))
103 {
104 assert(std::isnan(r.real()));
105 assert(std::isnan(r.imag()));
106 }
107 }
108}
109
110int main(int, char**)
111{
112 test<float>();
113 test<double>();
114 test<long double>();
115 test_edges();
116
117 return 0;
118}
119

source code of libcxx/test/std/numerics/complex.number/complex.transcendentals/cosh.pass.cpp