| 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/core/exponent.hpp> | ||
| 15 | |||
| 16 | namespace plf | ||
| 17 | { | ||
| 18 | |||
| 19 | template<typename Options> | ||
| 20 | struct mantissa_t : plf::elementwise_callable<mantissa_t, eve::mantissa_t, Options, raw_option, pedantic_option> | ||
| 21 | { | ||
| 22 | 44 | template<concepts::polyfloat_like Z> POLYFLOAT_ABI Z operator()(Z z) const noexcept { return POLYFLOAT_CALL(z); } | |
| 23 | |||
| 24 | 42 | POLYFLOAT_CALLABLE_OBJECT(mantissa_t, mantissa_); | |
| 25 | }; | ||
| 26 | //================================================================================================ | ||
| 27 | //! @addtogroup core | ||
| 28 | //! @{ | ||
| 29 | //! @var mantissa | ||
| 30 | //! @brief computes the IEEE mantissa of the floating value. | ||
| 31 | //! | ||
| 32 | //! @groupheader{Header file} | ||
| 33 | //! | ||
| 34 | //! @code | ||
| 35 | //! #include <eve/module/module/core.hpp> | ||
| 36 | //! @endcode | ||
| 37 | //! | ||
| 38 | //! @groupheader{Callable Signatures} | ||
| 39 | //! | ||
| 40 | //! @code | ||
| 41 | //! namespace eve | ||
| 42 | //! { | ||
| 43 | //! // Regular overload | ||
| 44 | //! constexpr auto mantissa(floating_value auto x) noexcept; // 1 | ||
| 45 | //! | ||
| 46 | //! // Lanes masking | ||
| 47 | //! constexpr auto mantissa[conditional_expr auto c](floating_value auto x) noexcept; // 2 | ||
| 48 | //! constexpr auto mantissa[logical_value auto m](floating_value auto x) noexcept; // 2 | ||
| 49 | //! | ||
| 50 | //! // Semantic options | ||
| 51 | //! constexpr auto mantissa[raw](floating_value auto x) noexcept; // 3 | ||
| 52 | //! } | ||
| 53 | //! @endcode | ||
| 54 | //! | ||
| 55 | //! **Parameters** | ||
| 56 | //! | ||
| 57 | //! * `x`: [real argument](@ref eve::value). | ||
| 58 | //! * `c`: [Conditional expression](@ref eve::conditional_expr) masking the operation. | ||
| 59 | //! * `m`: [Logical value](@ref eve::logical_value) masking the operation. | ||
| 60 | //! | ||
| 61 | //! **Return value** | ||
| 62 | //! | ||
| 63 | //! 1. The value of the IEEE mantissa is returned. In particular: | ||
| 64 | //! * `nan` returns nan | ||
| 65 | //! * \f$\pm\infty\f$ returns \f$\pm\1\f$. | ||
| 66 | //! * zero returns zero | ||
| 67 | //! 2. [The operation is performed conditionnaly](@ref conditional). | ||
| 68 | //! 3. The results for zero and nan are unspecified. | ||
| 69 | //! | ||
| 70 | //! | ||
| 71 | //! @note The `exponent` \f$e\f$ and `mantissa` \f$m\f$ of a floating point entry \f$x\f$ | ||
| 72 | //! are related by \f$x = m\times 2^e\f$, with \f$|m| \in \{0, nan\} \cup [1, 2[\f$. | ||
| 73 | //! | ||
| 74 | //! @groupheader{Example} | ||
| 75 | //! @godbolt{doc/core/mantissa.cpp} | ||
| 76 | //================================================================================================ | ||
| 77 | inline constexpr auto mantissa = eve::functor<mantissa_t>; | ||
| 78 | //================================================================================================ | ||
| 79 | //! @} | ||
| 80 | //================================================================================================ | ||
| 81 | |||
| 82 | namespace _ | ||
| 83 | { | ||
| 84 | template<typename Z, eve::callable_options O> | ||
| 85 | 42 | constexpr auto mantissa_(POLYFLOAT_DELAY(), O const& o, Z const& z) noexcept | |
| 86 | { | ||
| 87 | 42 | auto n = plf::exponent(z); | |
| 88 | 42 | auto h = eve::ldexp[o](hi(z), -n); | |
| 89 | if constexpr (dimension_v<Z> == 2) | ||
| 90 | { | ||
| 91 | 22 | auto l = eve::ldexp[o](lo(z), -n); | |
| 92 | 22 | return plf::_::from_pair(h, l); | |
| 93 | } | ||
| 94 | else if constexpr (dimension_v<Z> == 3) | ||
| 95 | { | ||
| 96 | 20 | auto m = eve::ldexp[o](md(z), -n); | |
| 97 | 20 | auto l = eve::ldexp[o](lo(z), -n); | |
| 98 | 20 | return plf::_::from_triple(h, m, l); | |
| 99 | } | ||
| 100 | } | ||
| 101 | } | ||
| 102 | } | ||
| 103 |