Janus 2.0.0
High-performance C++20 dual-mode numerical framework
Loading...
Searching...
No Matches
Trig.hpp
Go to the documentation of this file.
1#pragma once
7
9#include <Eigen/Dense>
10#include <cmath>
11
12namespace janus {
13
14// --- Sin ---
21template <JanusScalar T> T sin(const T &x) {
22 if constexpr (std::is_floating_point_v<T>) {
23 return std::sin(x);
24 } else {
25 return sin(x);
26 }
27}
28
35template <typename Derived> auto sin(const Eigen::MatrixBase<Derived> &x) {
36 return x.array().sin().matrix();
37}
38
39// --- Cos ---
46template <JanusScalar T> T cos(const T &x) {
47 if constexpr (std::is_floating_point_v<T>) {
48 return std::cos(x);
49 } else {
50 return cos(x);
51 }
52}
53
60template <typename Derived> auto cos(const Eigen::MatrixBase<Derived> &x) {
61 return x.array().cos().matrix();
62}
63
64// --- Tan ---
71template <JanusScalar T> T tan(const T &x) {
72 if constexpr (std::is_floating_point_v<T>) {
73 return std::tan(x);
74 } else {
75 return tan(x);
76 }
77}
78
85template <typename Derived> auto tan(const Eigen::MatrixBase<Derived> &x) {
86 return x.array().tan().matrix();
87}
88
89// --- Arcsin ---
96template <JanusScalar T> T asin(const T &x) {
97 if constexpr (std::is_floating_point_v<T>) {
98 return std::asin(x);
99 } else {
100 return asin(x);
101 }
102}
103
110template <typename Derived> auto asin(const Eigen::MatrixBase<Derived> &x) {
111 return x.array().asin().matrix();
112}
113
114// --- Arccos ---
121template <JanusScalar T> T acos(const T &x) {
122 if constexpr (std::is_floating_point_v<T>) {
123 return std::acos(x);
124 } else {
125 return acos(x);
126 }
127}
128
135template <typename Derived> auto acos(const Eigen::MatrixBase<Derived> &x) {
136 return x.array().acos().matrix();
137}
138
139// --- Arctan ---
146template <JanusScalar T> T atan(const T &x) {
147 if constexpr (std::is_floating_point_v<T>) {
148 return std::atan(x);
149 } else {
150 return atan(x);
151 }
152}
153
160template <typename Derived> auto atan(const Eigen::MatrixBase<Derived> &x) {
161 return x.array().atan().matrix();
162}
163
164// --- Atan2 ---
172template <JanusScalar T> T atan2(const T &y, const T &x) {
173 if constexpr (std::is_floating_point_v<T>) {
174 return std::atan2(y, x);
175 } else {
176 return atan2(y, x);
177 }
178}
179
180// --- Arcsinh ---
187template <JanusScalar T> T asinh(const T &x) {
188 if constexpr (std::is_floating_point_v<T>) {
189 return std::asinh(x);
190 } else {
191 return asinh(x);
192 }
193}
194
201template <typename Derived> auto asinh(const Eigen::MatrixBase<Derived> &x) {
202 using Scalar = typename Derived::Scalar;
203 if constexpr (std::is_same_v<Scalar, casadi::MX>) {
204 return x.unaryExpr([](const Scalar &v) { return asinh(v); });
205 } else {
206 return x.array().asinh().matrix();
207 }
208}
209
210// --- Arccosh ---
217template <JanusScalar T> T acosh(const T &x) {
218 if constexpr (std::is_floating_point_v<T>) {
219 return std::acosh(x);
220 } else {
221 return acosh(x);
222 }
223}
224
231template <typename Derived> auto acosh(const Eigen::MatrixBase<Derived> &x) {
232 using Scalar = typename Derived::Scalar;
233 if constexpr (std::is_same_v<Scalar, casadi::MX>) {
234 return x.unaryExpr([](const Scalar &v) { return acosh(v); });
235 } else {
236 return x.array().acosh().matrix();
237 }
238}
239
240// --- Arctanh ---
247template <JanusScalar T> T atanh(const T &x) {
248 if constexpr (std::is_floating_point_v<T>) {
249 return std::atanh(x);
250 } else {
251 return atanh(x);
252 }
253}
254
261template <typename Derived> auto atanh(const Eigen::MatrixBase<Derived> &x) {
262 using Scalar = typename Derived::Scalar;
263 if constexpr (std::is_same_v<Scalar, casadi::MX>) {
264 return x.unaryExpr([](const Scalar &v) { return atanh(v); });
265 } else {
266 return x.array().atanh().matrix();
267 }
268}
269
270} // namespace janus
C++20 concepts constraining valid Janus scalar types.
Definition Diagnostics.hpp:19
T atan(const T &x)
Computes arc tangent of x.
Definition Trig.hpp:146
T acos(const T &x)
Computes arc cosine of x.
Definition Trig.hpp:121
T tan(const T &x)
Computes tangent of x.
Definition Trig.hpp:71
T cos(const T &x)
Computes cosine of x.
Definition Trig.hpp:46
T asin(const T &x)
Computes arc sine of x.
Definition Trig.hpp:96
T sin(const T &x)
Computes sine of x.
Definition Trig.hpp:21
T asinh(const T &x)
Computes inverse hyperbolic sine of x.
Definition Trig.hpp:187
T atanh(const T &x)
Computes inverse hyperbolic tangent of x.
Definition Trig.hpp:247
T acosh(const T &x)
Computes inverse hyperbolic cosine of x.
Definition Trig.hpp:217
T atan2(const T &y, const T &x)
Computes arc tangent of y/x using signs of both arguments.
Definition Trig.hpp:172