| 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 | |||
| 14 | namespace plf | ||
| 15 | { | ||
| 16 | template<typename Options> | ||
| 17 | struct sqrteps_t : plf::constant_callable<sqrteps_t, eve::sqrteps_t, Options, lower_option, upper_option> | ||
| 18 | { | ||
| 19 | 8 | template<typename T> POLYFLOAT_ABI static constexpr auto value(eve::as<T> const&, auto const&) | |
| 20 | { | ||
| 21 | using u_t = eve::underlying_type_t<T>; | ||
| 22 | |||
| 23 | if constexpr (plf::dimension_v<T> == 2) | ||
| 24 | { | ||
| 25 | if constexpr (std::same_as<u_t, eve::float16_t>) return T(0x1p-10); | ||
| 26 | 2 | else if constexpr (std::same_as<u_t, float>) return T(0x1p-23); | |
| 27 | 2 | else if constexpr (std::same_as<u_t, double>) return T(0x1p-52); | |
| 28 | } | ||
| 29 | else if constexpr (plf::dimension_v<T> == 3) | ||
| 30 | { | ||
| 31 | if constexpr (std::same_as<u_t, eve::float16_t>) return T(0x1p-15); | ||
| 32 | else if constexpr (std::same_as<u_t, float>) | ||
| 33 | 2 | return plf::_::from_triple<u_t>(0x1.6a09e6p-35, 0x1.9fcef4p-61, -0x1.b7ba68p-86); | |
| 34 | 2 | else if constexpr (std::same_as<u_t, double>) return T(0x1p-78); | |
| 35 | } | ||
| 36 | else | ||
| 37 | { | ||
| 38 | return eve::sqrteps(eve::as<u_t>()); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | 12 | template<concepts::polyfloat_like T> POLYFLOAT_ABI constexpr T operator()(as<T> const& v) const | |
| 43 | { | ||
| 44 | 12 | return POLYFLOAT_CALL(v); | |
| 45 | } | ||
| 46 | |||
| 47 | POLYFLOAT_CALLABLE_OBJECT(sqrteps_t, sqrteps_); | ||
| 48 | }; | ||
| 49 | //====================================================================================================================== | ||
| 50 | //! @addtogroup constants | ||
| 51 | //! @{ | ||
| 52 | //! @var sqrteps | ||
| 53 | //! @brief return the sqrtepsolute value. | ||
| 54 | //! | ||
| 55 | //! @groupheader{Header file} | ||
| 56 | //! | ||
| 57 | //! @code | ||
| 58 | //! #include <polyfloat/core.hpp> | ||
| 59 | //! @endcode | ||
| 60 | //! | ||
| 61 | //! @groupheader{Callable Signatures} | ||
| 62 | //! | ||
| 63 | //! @code | ||
| 64 | //! namespace polyfloat | ||
| 65 | //! { | ||
| 66 | //! template<polyfloat::concepts::polyfloat_like T> constexpr auto sqrteps(T z) noexcept; | ||
| 67 | //! } | ||
| 68 | //! @endcode | ||
| 69 | //! | ||
| 70 | //! **Parameters** | ||
| 71 | //! | ||
| 72 | //! * `z`: Value to process. | ||
| 73 | //! | ||
| 74 | //! **Return value** | ||
| 75 | //! | ||
| 76 | //! Returns the sqrtepsolute value of z. | ||
| 77 | //! | ||
| 78 | //! @groupheader{Example} | ||
| 79 | //! | ||
| 80 | //! @godbolt{doc/core/sqrteps.cpp} | ||
| 81 | //====================================================================================================================== | ||
| 82 | |||
| 83 | inline constexpr auto sqrteps = eve::functor<sqrteps_t>; | ||
| 84 | //====================================================================================================================== | ||
| 85 | //! @} | ||
| 86 | //====================================================================================================================== | ||
| 87 | } | ||
| 88 |