| 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 Func> struct constant_t; | ||
| 17 | |||
| 18 | template<template<typename> typename Func, typename Opts> struct constant_t<Func<Opts>> : Func<Opts> | ||
| 19 | { | ||
| 20 | using base_callable = Func<Opts>; | ||
| 21 | |||
| 22 | template<typename T> | ||
| 23 | 2100 | constexpr auto operator[](T t) const | |
| 24 | requires(requires(base_callable const& b) { b[t]; }) | ||
| 25 | { | ||
| 26 |
1/1✓ Branch 1 taken 1052 times.
|
2100 | auto new_traits = base_callable::base::operator[](t); |
| 27 | 4200 | return constant_t<Func<decltype(new_traits)>>{new_traits}; | |
| 28 | } | ||
| 29 | |||
| 30 | template<concepts::real T> | ||
| 31 | 358 | constexpr T operator()(as<T> const& v) const | |
| 32 | requires(requires(base_callable const& b) { b(v); }) | ||
| 33 | { | ||
| 34 | 358 | return base_callable::operator()(v); | |
| 35 | } | ||
| 36 | |||
| 37 | template<concepts::polyfloat T> | ||
| 38 | 155616 | constexpr T operator()(as<T> const&) const | |
| 39 | requires(requires(base_callable const& b) { b(plf::as_component<T>{}); }) | ||
| 40 | { | ||
| 41 |
1/1✓ Branch 2 taken 77808 times.
|
155616 | return T{base_callable::operator()(as_component<T>{})}; |
| 42 | } | ||
| 43 | |||
| 44 | POLYFLOAT_CALLABLE_OBJECT(constant_t, constant_); | ||
| 45 | }; | ||
| 46 | |||
| 47 | template<auto Constant> inline constexpr constant_t<eve::tag_t<Constant>> as_constant = {}; | ||
| 48 | } | ||
| 49 | |||
| 50 | //====================================================================================================================== | ||
| 51 | // List of all EVE constants we re-propagate | ||
| 52 | //====================================================================================================================== | ||
| 53 | namespace plf | ||
| 54 | { | ||
| 55 | //==================================================================================================================== | ||
| 56 | //! @addtogroup core | ||
| 57 | //! @{ | ||
| 58 | //! @var allbits | ||
| 59 | //! @brief every bit set, which is the pattern of a quiet NaN for a floating point type, for the requested polyfloat type. | ||
| 60 | //! | ||
| 61 | //! @var bitincrement | ||
| 62 | //! @brief the smallest increment representable in the type's bit pattern, for the requested polyfloat type. | ||
| 63 | //! | ||
| 64 | //! @var half | ||
| 65 | //! @brief one half, for the requested polyfloat type. | ||
| 66 | //! | ||
| 67 | //! @var inf | ||
| 68 | //! @brief positive infinity, for the requested polyfloat type. | ||
| 69 | //! | ||
| 70 | //! @var mhalf | ||
| 71 | //! @brief minus one half, for the requested polyfloat type. | ||
| 72 | //! | ||
| 73 | //! @var mindenormal | ||
| 74 | //! @brief the smallest denormal value, for the requested polyfloat type. | ||
| 75 | //! | ||
| 76 | //! @var minexponent | ||
| 77 | //! @brief the smallest exponent of the type, for the requested polyfloat type. | ||
| 78 | //! | ||
| 79 | //! @var minf | ||
| 80 | //! @brief negative infinity, for the requested polyfloat type. | ||
| 81 | //! | ||
| 82 | //! @var mone | ||
| 83 | //! @brief minus one, for the requested polyfloat type. | ||
| 84 | //! | ||
| 85 | //! @var mzero | ||
| 86 | //! @brief negative zero, for the requested polyfloat type. | ||
| 87 | //! | ||
| 88 | //! @var nan | ||
| 89 | //! @brief a quiet NaN, for the requested polyfloat type. | ||
| 90 | //! | ||
| 91 | //! @var one | ||
| 92 | //! @brief one, for the requested polyfloat type. | ||
| 93 | //! | ||
| 94 | //! @var smallestposval | ||
| 95 | //! @brief the smallest positive normal value, for the requested polyfloat type. | ||
| 96 | //! | ||
| 97 | //! @var false_ | ||
| 98 | //! @brief the false logical value, for the requested polyfloat type. | ||
| 99 | //! | ||
| 100 | //! @var true_ | ||
| 101 | //! @brief the true logical value, for the requested polyfloat type. | ||
| 102 | //! | ||
| 103 | //! @var zero | ||
| 104 | //! @brief zero, for the requested polyfloat type. | ||
| 105 | //! | ||
| 106 | //! @} | ||
| 107 | //==================================================================================================================== | ||
| 108 | |||
| 109 | // Direct reuse | ||
| 110 | using eve::false_; | ||
| 111 | using eve::true_; | ||
| 112 | using eve::zero; | ||
| 113 | |||
| 114 | // Wrapping required | ||
| 115 | // from eve::core | ||
| 116 | inline constexpr auto allbits = _::as_constant<eve::allbits>; | ||
| 117 | inline constexpr auto bitincrement = _::as_constant<eve::bitincrement>; | ||
| 118 | inline constexpr auto half = _::as_constant<eve::half>; | ||
| 119 | inline constexpr auto mhalf = _::as_constant<eve::mhalf>; | ||
| 120 | inline constexpr auto mindenormal = _::as_constant<eve::mindenormal>; | ||
| 121 | inline constexpr auto minexponent = _::as_constant<eve::minexponent>; | ||
| 122 | |||
| 123 | inline constexpr auto maxexponent = _::as_constant<eve::maxexponent>; | ||
| 124 | inline constexpr auto maxexponentp1 = _::as_constant<eve::maxexponentp1>; | ||
| 125 | inline constexpr auto maxexponentm1 = _::as_constant<eve::maxexponentm1>; | ||
| 126 | inline constexpr auto mone = _::as_constant<eve::mone>; | ||
| 127 | inline constexpr auto mzero = _::as_constant<eve::mzero>; | ||
| 128 | inline constexpr auto one = _::as_constant<eve::one>; | ||
| 129 | inline constexpr auto smallestposval = _::as_constant<eve::smallestposval>; | ||
| 130 | } | ||
| 131 |