| 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 | |||
| 15 | namespace plf | ||
| 16 | { | ||
| 17 | |||
| 18 | template<typename Options> struct exponent_t : eve::callable<exponent_t, Options, raw_option, pedantic_option> | ||
| 19 | { | ||
| 20 | template<concepts::polyfloat_like Z> | ||
| 21 | 586 | POLYFLOAT_ABI eve::as_integer_t<as_component_type_t<Z>, signed> operator()(Z z) const noexcept | |
| 22 | { | ||
| 23 | 586 | return POLYFLOAT_CALL(z); | |
| 24 | } | ||
| 25 | |||
| 26 | 586 | POLYFLOAT_CALLABLE_OBJECT(exponent_t, exponent_); | |
| 27 | }; | ||
| 28 | |||
| 29 | //================================================================================================ | ||
| 30 | //! @addtogroup core_internal | ||
| 31 | //! @{ | ||
| 32 | //! @var exponent | ||
| 33 | //! @brief `elementwise_callable` object computing the integral IEEE exponent of the floating value. | ||
| 34 | //! | ||
| 35 | //! @groupheader{Header file} | ||
| 36 | //! | ||
| 37 | //! @code | ||
| 38 | //! #include <eve/module/module/core.hpp> | ||
| 39 | //! @endcode | ||
| 40 | //! | ||
| 41 | //! @groupheader{Callable Signatures} | ||
| 42 | //! | ||
| 43 | //! @code | ||
| 44 | //! namespace eve | ||
| 45 | //! { | ||
| 46 | //! // Regular overload | ||
| 47 | //! constexpr auto exponent(floating_value auto x) noexcept; // 1 | ||
| 48 | //! | ||
| 49 | //! // Semantic options | ||
| 50 | //! constexpr auto exponent[raw](floating_value auto x) noexcept; // 2 | ||
| 51 | //! } | ||
| 52 | //! @endcode | ||
| 53 | //! | ||
| 54 | //! **Parameters** | ||
| 55 | //! | ||
| 56 | //! * `x` : [argument](@ref eve::floating_value). | ||
| 57 | //! | ||
| 58 | //! **Return value** | ||
| 59 | //! | ||
| 60 | //! 1. The value of the IEEE exponent is returned. In particular: | ||
| 61 | //! * `inf`, `minf` and `nan` return `maxexponent` plus 1 | ||
| 62 | //! * zero returns zero | ||
| 63 | //! 2 identical except that results for zero, nan and infinite inputs are unspecified | ||
| 64 | //! | ||
| 65 | //! @note The exponent \f$e\f$ and mantissa \f$m\f$ of a floating point entry \f$x\f$ are related by | ||
| 66 | //! \f$x = m\times 2^e\f$, with \f$|m| \in \{0\} \cup [1, 2[\f$. | ||
| 67 | //! | ||
| 68 | //! @groupheader{Example} | ||
| 69 | //! @godbolt{doc/core/exponent.cpp} | ||
| 70 | //================================================================================================ | ||
| 71 | inline constexpr auto exponent = eve::functor<exponent_t>; | ||
| 72 | //================================================================================================ | ||
| 73 | //! @} | ||
| 74 | //================================================================================================ | ||
| 75 | |||
| 76 | namespace _ | ||
| 77 | { | ||
| 78 | template<typename Z, eve::callable_options O> | ||
| 79 | 586 | constexpr auto exponent_(POLYFLOAT_DELAY(), O const&, Z const& z) noexcept | |
| 80 | { | ||
| 81 | 586 | return eve::exponent(hi(z)); | |
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 |