| 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 frexp_t : plf::callable<frexp_t, eve::frexp_t, Options, raw_option, pedantic_option> | ||
| 19 | { | ||
| 20 | template<concepts::polyfloat_like Z> | ||
| 21 | 41374 | POLYFLOAT_ABI auto operator()(Z z) const noexcept -> eve::zipped<Z, as_component_type_t<Z>> | |
| 22 | { | ||
| 23 | 41374 | return POLYFLOAT_CALL(z); | |
| 24 | } | ||
| 25 | |||
| 26 | 41372 | POLYFLOAT_CALLABLE_OBJECT(frexp_t, frexp_); | |
| 27 | }; | ||
| 28 | //================================================================================================ | ||
| 29 | //! @addtogroup core | ||
| 30 | //! @{ | ||
| 31 | //! @var frexp | ||
| 32 | //! @brief `elementwise_callable` computing pair of mantissa and exponent of a polyfloat value, | ||
| 33 | //! | ||
| 34 | //! @groupheader{Header file} | ||
| 35 | //! | ||
| 36 | //! @code | ||
| 37 | //! #include <eve/module/module/core.hpp> | ||
| 38 | //! @endcode | ||
| 39 | //! | ||
| 40 | //! @groupheader{Callable Signatures} | ||
| 41 | //! | ||
| 42 | //! @code | ||
| 43 | //! namespace eve | ||
| 44 | //! { | ||
| 45 | //! // Regular overload | ||
| 46 | //! constexpr auto frexp(floating_value auto x) noexcept; // 1 | ||
| 47 | //! | ||
| 48 | //! // Lanes masking | ||
| 49 | //! constexpr auto frexp[conditional_expr auto c](floating_value auto x) noexcept; // 2 | ||
| 50 | //! constexpr auto frexp[logical_value auto m](floating_value auto x) noexcept; // 2 | ||
| 51 | //! | ||
| 52 | //! // Semantic options | ||
| 53 | //! constexpr auto frexp[pedantic](floating_value x) noexcept; // 3 | ||
| 54 | //! } | ||
| 55 | //! @endcode | ||
| 56 | //! | ||
| 57 | //! **Parameters** | ||
| 58 | //! | ||
| 59 | //! * `x`: [value](@ref eve::value). | ||
| 60 | //! * `c`: [Conditional expression](@ref eve::conditional_expr) masking the operation. | ||
| 61 | //! * `m`: [Logical value](@ref eve::logical_value) masking the operation. | ||
| 62 | //! | ||
| 63 | //! **Return value** | ||
| 64 | //! | ||
| 65 | //! 1. returns a kumi::tuple `{m,e}` of values of the same type as `x`, which are related by | ||
| 66 | //! \f$x = m\times 2^e\f$, with \f$|m| \in [0.5, 1.5[\f$. | ||
| 67 | //! However, the cases \f$x = \pm\infty\f$ or is a Nan or a denormal are undefined. | ||
| 68 | //! 2. [The operation is performed conditionnaly](@ref conditional). | ||
| 69 | //! 3. this option takes also properly care of the cases where | ||
| 70 | //! \f$x = \pm0, \pm\infty\f$ or is a Nan, where \f$m=x\f$ and \f$e=0\f$ and of the | ||
| 71 | //! denormal cases. | ||
| 72 | //! | ||
| 73 | //! @note the exponent part is always taken from the `hi` part of the input. | ||
| 74 | //! | ||
| 75 | //! @groupheader{External references} | ||
| 76 | //! * [C++ standard reference](https://en.cppreference.com/w/cpp/numeric/math/frexp) | ||
| 77 | //! | ||
| 78 | //! @groupheader{Example} | ||
| 79 | //! @godbolt{doc/core/frexp.cpp} | ||
| 80 | //================================================================================================ | ||
| 81 | inline constexpr auto frexp = eve::functor<frexp_t>; | ||
| 82 | //================================================================================================ | ||
| 83 | //! @} | ||
| 84 | //================================================================================================ | ||
| 85 | |||
| 86 | namespace _ | ||
| 87 | { | ||
| 88 | template<typename Z, eve::callable_options O> | ||
| 89 | 41372 | constexpr auto frexp_(POLYFLOAT_DELAY(), O const& o, Z const& z) noexcept | |
| 90 | { | ||
| 91 | 82589 | auto [h, n] = eve::frexp[o](hi(z)); | |
| 92 | if constexpr (dimension_v<Z> == 2) | ||
| 93 | { | ||
| 94 | 4817 | auto l = eve::ldexp[o](lo(z), -n); | |
| 95 | 4817 | return kumi::tuple{_::from_pair(h, l), n}; | |
| 96 | } | ||
| 97 | else if constexpr (dimension_v<Z> == 3) | ||
| 98 | { | ||
| 99 | 36555 | auto l = eve::ldexp[o](lo(z), -n); | |
| 100 | 36555 | auto m = eve::ldexp[o](md(z), -n); | |
| 101 | 36555 | return kumi::tuple{_::from_triple(h, m, l), n}; | |
| 102 | } | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
| 106 |