WPILibC++ 2023.4.3-108-ge5452e3
acosh.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 cosine function
23 */
24
25#ifndef _gcem_acosh_HPP
26#define _gcem_acosh_HPP
27
28namespace internal
29{
30
31template<typename T>
32constexpr
33T
34acosh_compute(const T x)
35noexcept
36{
37 return( // NaN check
38 is_nan(x) ? \
39 GCLIM<T>::quiet_NaN() :
40 // function defined for x >= 1
41 x < T(1) ? \
42 GCLIM<T>::quiet_NaN() :
43 // indistinguishable from 1
44 GCLIM<T>::min() > abs(x - T(1)) ? \
45 T(0) :
46 // else
47 log( x + sqrt(x*x - T(1)) ) );
48}
49
50}
51
52/**
53 * Compile-time inverse hyperbolic cosine function
54 *
55 * @param x a real-valued input.
56 * @return the inverse hyperbolic cosine function using \f[ \text{acosh}(x) = \ln \left( x + \sqrt{x^2 - 1} \right) \f]
57 */
58
59template<typename T>
60constexpr
61return_t<T>
62acosh(const T x)
63noexcept
64{
65 return internal::acosh_compute( static_cast<return_t<T>>(x) );
66}
67
68#endif
constexpr return_t< T > acosh(const T x) noexcept
Compile-time inverse hyperbolic cosine function.
Definition: acosh.hpp:62
UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition: math.h:721
auto sqrt(const UnitType &value) noexcept -> unit_t< square_root< typename units::traits::unit_t_traits< UnitType >::unit_type >, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the square root of value
Definition: math.h:483
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 acosh_compute(const T x) noexcept
Definition: acosh.hpp:34