| 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 <eve/eve.hpp> | ||
| 11 | #include <polyfloat/details/callable.hpp> | ||
| 12 | #include <polyfloat/types/concepts.hpp> | ||
| 13 | #include <polyfloat/types/traits.hpp> | ||
| 14 | namespace plf | ||
| 15 | { | ||
| 16 | template<typename Options> | ||
| 17 | struct valmax_t : plf::constant_callable<valmax_t, eve::valmax_t, Options, lower_option, upper_option> | ||
| 18 | { | ||
| 19 | 9 | template<typename T> POLYFLOAT_ABI static constexpr T value(eve::as<T> const&, auto const&) | |
| 20 | { | ||
| 21 | using u_t = eve::underlying_type_t<T>; | ||
| 22 |
1/1✓ Branch 2 taken 5 times.
|
9 | auto vlm = eve::valmax(eve::as<u_t>()); |
| 23 | if constexpr (dimension_v<T> == 2) | ||
| 24 | { | ||
| 25 |
1/1✓ Branch 2 taken 3 times.
|
5 | auto mnbts = -plf::effective_mantissa_bits(eve::as<u_t>()); |
| 26 | 5 | return plf::_::from_pair(vlm, eve::ldexp(vlm, mnbts)); | |
| 27 | } | ||
| 28 | else if constexpr (dimension_v<T> == 3) | ||
| 29 | { | ||
| 30 |
1/1✓ Branch 2 taken 2 times.
|
4 | auto mnbts = -plf::effective_mantissa_bits(eve::as<u_t>()); |
| 31 | 4 | return plf::_::from_triple(vlm, eve::ldexp(vlm, mnbts), eve::ldexp(vlm, 2 * mnbts - 1)); | |
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | 9 | template<concepts::polyfloat_like T> POLYFLOAT_ABI constexpr T operator()(as<T> const& v) const | |
| 36 | { | ||
| 37 | 9 | return POLYFLOAT_CALL(v); | |
| 38 | } | ||
| 39 | |||
| 40 | POLYFLOAT_CALLABLE_OBJECT(valmax_t, valmax_); | ||
| 41 | }; | ||
| 42 | //====================================================================================================================== | ||
| 43 | //! @addtogroup constants | ||
| 44 | //! @{ | ||
| 45 | //! @var valmax | ||
| 46 | //! @brief return the maximal representable flint value. | ||
| 47 | //! | ||
| 48 | //! @groupheader{Header file} | ||
| 49 | //! | ||
| 50 | //! @code | ||
| 51 | //! #include <polyfloat/core.hpp> | ||
| 52 | //! @endcode | ||
| 53 | //! | ||
| 54 | //! @groupheader{Callable Signatures} | ||
| 55 | //! | ||
| 56 | //! @code | ||
| 57 | //! namespace polyfloat | ||
| 58 | //! { | ||
| 59 | //! template<polyfloat::concepts::polyfloat_like T> constexpr auto valmax(T z) noexcept; | ||
| 60 | //! } | ||
| 61 | //! @endcode | ||
| 62 | //! | ||
| 63 | //! **Parameters** | ||
| 64 | //! | ||
| 65 | //! * `z` : [Type wrapper](@ref eve::as) instance embedding the type of the constant. | ||
| 66 | //! | ||
| 67 | //! **Return value** | ||
| 68 | //! | ||
| 69 | //! Returns the effective number of bits of the mantissa value. | ||
| 70 | //! | ||
| 71 | //! @groupheader{Example} | ||
| 72 | //! | ||
| 73 | //! @godbolt{doc/core/valmax.cpp} | ||
| 74 | //====================================================================================================================== | ||
| 75 | |||
| 76 | inline constexpr auto valmax = eve::functor<valmax_t>; | ||
| 77 | //====================================================================================================================== | ||
| 78 | //! @} | ||
| 79 | //====================================================================================================================== | ||
| 80 | } | ||
| 81 |