WPILibC++ 2023.4.3-108-ge5452e3
sinh.hpp
Go to the documentation of this file.
1/*################################################################################
2 ##
3 ## Copyright (C) 2016-2022 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21/*
22 * compile-time hyperbolic sine function
23 */
24
25#ifndef _gcem_sinh_HPP
26#define _gcem_sinh_HPP
27
28namespace internal
29{
30
31template<typename T>
32constexpr
33T
34sinh_check(const T x)
35noexcept
36{
37 return( // NaN check
38 is_nan(x) ? \
39 GCLIM<T>::quiet_NaN() :
40 // indistinguishable from zero
41 GCLIM<T>::min() > abs(x) ? \
42 T(0) :
43 // else
44 (exp(x) - exp(-x))/T(2) );
45}
46
47}
48
49/**
50 * Compile-time hyperbolic sine function
51 *
52 * @param x a real-valued input.
53 * @return the hyperbolic sine function using \f[ \sinh(x) = \frac{\exp(x) - \exp(-x)}{2} \f]
54 */
55
56template<typename T>
57constexpr
58return_t<T>
59sinh(const T x)
60noexcept
61{
62 return internal::sinh_check( static_cast<return_t<T>>(x) );
63}
64
65#endif
UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition: math.h:721
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
Definition: Eigen_Colamd.h:50
constexpr bool is_nan(const T x) noexcept
Definition: is_nan.hpp:36
constexpr T sinh_check(const T x) noexcept
Definition: sinh.hpp:34
constexpr return_t< T > sinh(const T x) noexcept
Compile-time hyperbolic sine function.
Definition: sinh.hpp:59