| 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/abs.hpp> | ||
| 15 | #include <polyfloat/module/core/is_infinite.hpp> | ||
| 16 | #include <polyfloat/module/core/is_eqz.hpp> | ||
| 17 | #include <polyfloat/module/core/max.hpp> | ||
| 18 | |||
| 19 | namespace plf | ||
| 20 | { | ||
| 21 | |||
| 22 | template<typename Options> | ||
| 23 | struct reldist_t : eve::strict_elementwise_callable<reldist_t, Options, raw_option, pedantic_option> | ||
| 24 | { | ||
| 25 | template<concepts::polyfloat_like Z1, concepts::polyfloat_like Z2> | ||
| 26 | 46382 | POLYFLOAT_ABI constexpr as_polyfloat_like_t<Z1, Z2> operator()(Z1 z1, Z2 z2) const noexcept | |
| 27 | { | ||
| 28 | 46382 | return POLYFLOAT_CALL(z1, z2); | |
| 29 | } | ||
| 30 | |||
| 31 | 46382 | POLYFLOAT_CALLABLE_OBJECT(reldist_t, reldist_); | |
| 32 | }; | ||
| 33 | //====================================================================================================================== | ||
| 34 | //! @addtogroup core | ||
| 35 | //! @{ | ||
| 36 | //! @var reldist | ||
| 37 | //! @brief return the relative distance value. | ||
| 38 | //! | ||
| 39 | //! @groupheader{Header file} | ||
| 40 | //! | ||
| 41 | //! @code | ||
| 42 | //! #include <polyfloat/core.hpp> | ||
| 43 | //! @endcode | ||
| 44 | //! | ||
| 45 | //! @groupheader{Callable Signatures} | ||
| 46 | //! | ||
| 47 | //! @code | ||
| 48 | //! namespace polyfloat | ||
| 49 | //! { | ||
| 50 | //! template<polyfloat::concepts::polyfloat_like T1, polyfloat_like Z2> constexpr auto reldist(T1 z1, T2 z2) noexcept; | ||
| 51 | //! } | ||
| 52 | //! @endcode | ||
| 53 | //! | ||
| 54 | //! **Parameters** | ||
| 55 | //! | ||
| 56 | //! * `z`: Value to process. | ||
| 57 | //! | ||
| 58 | //! **Return value** | ||
| 59 | //! | ||
| 60 | //! Returns the the relative distance computed as the absolute value of the arguments difference given by `dist` | ||
| 61 | //! divided by the maximum of their absolute values and 1. | ||
| 62 | //! | ||
| 63 | //! @groupheader{Example} | ||
| 64 | //! | ||
| 65 | //! @godbolt{doc/core/reldist.cpp} | ||
| 66 | //====================================================================================================================== | ||
| 67 | |||
| 68 | inline constexpr auto reldist = eve::functor<reldist_t>; | ||
| 69 | //====================================================================================================================== | ||
| 70 | //! @} | ||
| 71 | //====================================================================================================================== | ||
| 72 | } | ||
| 73 | |||
| 74 | namespace plf::_ | ||
| 75 | { | ||
| 76 | template<typename Z1, typename Z2, eve::callable_options O> | ||
| 77 | 46382 | constexpr auto reldist_(POLYFLOAT_DELAY(), O const& o, Z1 const& z1, Z2 const& z2) noexcept | |
| 78 | { | ||
| 79 | 46382 | auto d = dist[o](z1, z2); | |
| 80 | 46382 | return if_else(is_infinite(d) || is_eqz(d), d, d / plf::max(abs(z1), abs(z2), eve::one(eve::as(abs(hi(z1)))))); | |
| 81 | } | ||
| 82 | } | ||
| 83 |