| 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 <eve/module/core/regular/if_else.hpp> | ||
| 15 | |||
| 16 | namespace plf | ||
| 17 | { | ||
| 18 | |||
| 19 | template<typename Options> struct chi_t : eve::strict_tuple_callable<chi_t, Options, raw_option, pedantic_option> | ||
| 20 | { | ||
| 21 | template<typename... Ts> struct result : as_polyfloat_like<Ts...> | ||
| 22 | { | ||
| 23 | }; | ||
| 24 | |||
| 25 | template<concepts::polyfloat_like Z0, concepts::polyfloat_like Z1, concepts::polyfloat_like Z2> | ||
| 26 | 30 | POLYFLOAT_ABI typename result<Z0, Z1, Z2>::type constexpr operator()(Z0 z0, Z1 z1, Z2 z2) const noexcept | |
| 27 | { | ||
| 28 | 30 | return POLYFLOAT_CALL(z0, z1, z2); | |
| 29 | } | ||
| 30 | |||
| 31 | template<concepts::polyfloat_like T, typename B> | ||
| 32 | 12 | POLYFLOAT_ABI T constexpr operator()(T a, B const& belongs) const noexcept | |
| 33 | { | ||
| 34 | 12 | return POLYFLOAT_CALL(a, belongs); | |
| 35 | } | ||
| 36 | |||
| 37 | 36 | POLYFLOAT_CALLABLE_OBJECT(chi_t, chi_); | |
| 38 | }; | ||
| 39 | //====================================================================================================================== | ||
| 40 | //! @addtogroup core | ||
| 41 | //! @{ | ||
| 42 | //! @var chi | ||
| 43 | //! @brief indicatrix of the interval \f$[lo, hi[\f$ or | ||
| 44 | //! of the set for which the invocable returns true. | ||
| 45 | //! | ||
| 46 | //! @groupheader{Header file} | ||
| 47 | //! | ||
| 48 | //! @code | ||
| 49 | //! #include <polyfloat/core.hpp> | ||
| 50 | //! @endcode | ||
| 51 | //! | ||
| 52 | //! @groupheader{Callable Signatures} | ||
| 53 | //! | ||
| 54 | //! @code | ||
| 55 | //! namespace polyfloat | ||
| 56 | //! { | ||
| 57 | //! constexpr auto chi(value auto x, value auto lo, value auto hi) noexcept; // 1 | ||
| 58 | //! constexpr auto chi(value auto x, auto belongs) noexcept; // 2 | ||
| 59 | //! | ||
| 60 | //! } | ||
| 61 | //! @endcode | ||
| 62 | //! | ||
| 63 | //! **Parameters** | ||
| 64 | //! | ||
| 65 | //! * `x`: value to chi. | ||
| 66 | //! * `lo`, `hi`: [the boundary values](@ref eve::value) of the interval. | ||
| 67 | //! * `belongs`: predicate function | ||
| 68 | //! * `c`: [Conditional expression](@ref eve::conditional_expr) masking the operation. | ||
| 69 | //! * `m`: [Logical value](@ref eve::logical_value) masking the operation. | ||
| 70 | //! | ||
| 71 | //! **Return value** | ||
| 72 | //! 1. Each [element](@ref glossary_elementwise) of the result contains: | ||
| 73 | //! * `0`, if `x` is less than `lo`. or if `hi` is strictly less than `x`. | ||
| 74 | //! * `1` otherwise. | ||
| 75 | //! 2 1 in the type of x if belongs(x) evaluate to true else 0. | ||
| 76 | //! | ||
| 77 | //! @groupheader{Example} | ||
| 78 | //! | ||
| 79 | //! @godbolt{doc/core/chi.cpp} | ||
| 80 | //====================================================================================================================== | ||
| 81 | |||
| 82 | inline constexpr auto chi = eve::functor<chi_t>; | ||
| 83 | //====================================================================================================================== | ||
| 84 | //! @} | ||
| 85 | //====================================================================================================================== | ||
| 86 | } | ||
| 87 | |||
| 88 | namespace plf::_ | ||
| 89 | { | ||
| 90 | template<typename T0, typename T1, typename T2, eve::callable_options O> | ||
| 91 | 20 | constexpr auto chi_(POLYFLOAT_DELAY(), O const& c, T0 a, T1 l, T2 h) noexcept | |
| 92 | { | ||
| 93 | using r_t = as_polyfloat_like_t<T0, T1, T2>; | ||
| 94 | using u_t = eve::element_type_t<r_t>; | ||
| 95 | 64 | auto cvt = [](auto a) { return plf::convert(a, as<u_t>()); }; | |
| 96 | 20 | auto z = if_else(cvt(a) < cvt(h) && cvt(a) >= cvt(l), r_t(1), eve::zero); | |
| 97 | if constexpr (O::contains(eve::condition_key)) return mask_op(c[eve::condition_key], eve::_::return_2nd, a, z); | ||
| 98 | 20 | else return z; | |
| 99 | } | ||
| 100 | |||
| 101 | template<typename T, typename B, eve::callable_options O> | ||
| 102 | 12 | constexpr auto chi_(POLYFLOAT_DELAY(), O const& c, T x, B const& b) noexcept | |
| 103 | { | ||
| 104 | 12 | auto z = if_else(b(x), T(1), eve::zero); | |
| 105 | if constexpr (O::contains(eve::condition_key)) return mask_op(c[eve::condition_key], eve::_::return_2nd, x, z); | ||
| 106 | 12 | else return z; | |
| 107 | } | ||
| 108 | |||
| 109 | } | ||
| 110 |