WPILibC++ 2023.4.3
atanh.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 inverse hyperbolic tangent function
23 */
24
25#ifndef _gcem_atanh_HPP
26#define _gcem_atanh_HPP
27
28namespace internal
29{
30
31template<typename T>
32constexpr
33T
34atanh_compute(const T x)
35noexcept
36{
37 return( log( (T(1) + x)/(T(1) - x) ) / T(2) );
38}
39
40template<typename T>
41constexpr
42T
43atanh_check(const T x)
44noexcept
45{
46 return( // NaN check
47 is_nan(x) ? \
48 GCLIM<T>::quiet_NaN() :
49 // function is defined for |x| < 1
50 T(1) < abs(x) ? \
51 GCLIM<T>::quiet_NaN() :
52 GCLIM<T>::min() > (T(1) - abs(x)) ? \
53 sgn(x)*GCLIM<T>::infinity() :
54 // indistinguishable from zero
55 GCLIM<T>::min() > abs(x) ? \
56 T(0) :
57 // else
58 atanh_compute(x) );
59}
60
61}
62
63/**
64 * Compile-time inverse hyperbolic tangent function
65 *
66 * @param x a real-valued input.
67 * @return the inverse hyperbolic tangent function using \f[ \text{atanh}(x) = \frac{1}{2} \ln \left( \frac{1+x}{1-x} \right) \f]
68 */
69
70template<typename T>
71constexpr
72return_t<T>
73atanh(const T x)
74noexcept
75{
76 return internal::atanh_check( static_cast<return_t<T>>(x) );
77}
78
79#endif
constexpr return_t< T > atanh(const T x) noexcept
Compile-time inverse hyperbolic tangent function.
Definition: atanh.hpp:73
UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition: math.h:721
dimensionless::scalar_t log(const ScalarUnit x) noexcept
Compute natural logarithm.
Definition: math.h:349
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 atanh_check(const T x) noexcept
Definition: atanh.hpp:43
constexpr T atanh_compute(const T x) noexcept
Definition: atanh.hpp:34
constexpr int sgn(const T x) noexcept
Compile-time sign function.
Definition: sgn.hpp:34