| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | /* | ||
| 3 | POLYFLOAT - Extended precision floating points | ||
| 4 | Copyright : POLYFLOAT Contributors & Maintainers | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //====================================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | #include <polyfloat/details/callable.hpp> | ||
| 11 | #include <polyfloat/types/concepts.hpp> | ||
| 12 | #include <polyfloat/types/traits.hpp> | ||
| 13 | #include <type_traits> | ||
| 14 | #include <polyfloat/module/math/exp.hpp> | ||
| 15 | |||
| 16 | namespace plf | ||
| 17 | { | ||
| 18 | |||
| 19 | template<typename Options> | ||
| 20 | struct sinh_t : plf::elementwise_callable<sinh_t, eve::sinh_t, Options, raw_option, pedantic_option> | ||
| 21 | { | ||
| 22 | 158 | template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept | |
| 23 | { | ||
| 24 | 158 | return POLYFLOAT_CALL(z); | |
| 25 | } | ||
| 26 | |||
| 27 | 148 | POLYFLOAT_CALLABLE_OBJECT(sinh_t, sinh_); | |
| 28 | }; | ||
| 29 | //====================================================================================================================== | ||
| 30 | //! @addtogroup math | ||
| 31 | //! @{ | ||
| 32 | //! @var sinh | ||
| 33 | //! @brief return the hyperbolic sine value. | ||
| 34 | //! | ||
| 35 | //! @groupheader{Header file} | ||
| 36 | //! | ||
| 37 | //! @code | ||
| 38 | //! #include <polyfloat/core.hpp> | ||
| 39 | //! @endcode | ||
| 40 | //! | ||
| 41 | //! @groupheader{Callable Signatures} | ||
| 42 | //! | ||
| 43 | //! @code | ||
| 44 | //! namespace polyfloat | ||
| 45 | //! { | ||
| 46 | //! template<polyfloat::concepts::polyfloat_like T> constexpr auto sinh(T z) noexcept; | ||
| 47 | //! } | ||
| 48 | //! @endcode | ||
| 49 | //! | ||
| 50 | //! **Parameters** | ||
| 51 | //! | ||
| 52 | //! * `z`: Value to process. | ||
| 53 | //! | ||
| 54 | //! **Return value** | ||
| 55 | //! | ||
| 56 | //! Returns the hyperbolic sine of z. | ||
| 57 | //! | ||
| 58 | //! @groupheader{Example} | ||
| 59 | //! | ||
| 60 | //! @godbolt{doc/math/sinh.cpp} | ||
| 61 | //====================================================================================================================== | ||
| 62 | |||
| 63 | inline constexpr auto sinh = eve::functor<sinh_t>; | ||
| 64 | //====================================================================================================================== | ||
| 65 | //! @} | ||
| 66 | //====================================================================================================================== | ||
| 67 | } | ||
| 68 | |||
| 69 | namespace plf::_ | ||
| 70 | { | ||
| 71 | |||
| 72 | 148 | template<typename T, eve::callable_options O> constexpr auto sinh_(POLYFLOAT_DELAY(), O const& o, T a0) noexcept | |
| 73 | { | ||
| 74 | using u_t = eve::underlying_type_t<T>; | ||
| 75 | 148 | auto inf = is_not_finite(a0); | |
| 76 | 148 | auto x = plf::abs(a0); | |
| 77 | 148 | auto h = plf::if_else(is_gtz(a0), one(eve::as<u_t>()), mone); | |
| 78 | 148 | auto t = plf::exp(x) - 1; //plf::expm1(x); | |
| 79 | 148 | auto inct = plf::inc(t); | |
| 80 | 148 | auto u = t / inct; | |
| 81 | 148 | auto z = fnma(t, u, t); | |
| 82 | 148 | auto s = h * plf::average(z, t); | |
| 83 | |||
| 84 | 148 | s = if_else(is_eqz(a0), a0, s); | |
| 85 | 148 | auto test = x < maxlog(as<T>()) || inf; | |
| 86 |
2/2✓ Branch 1 taken 70 times.
✓ Branch 2 taken 4 times.
|
148 | if (eve::all(test)) return if_else(inf, a0, s); |
| 87 | 8 | auto w = exp[o](x * half(eve::as<u_t>())); | |
| 88 | 8 | t = half(eve::as<u_t>()) * w; | |
| 89 | 8 | t *= w; | |
| 90 | |||
| 91 | 8 | s = if_else(test, s, t * h); | |
| 92 | 8 | return if_else(inf, a0, s); | |
| 93 | } | ||
| 94 | } | ||
| 95 |