| 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 | |||
| 16 | namespace plf | ||
| 17 | { | ||
| 18 | |||
| 19 | template<typename Options> | ||
| 20 | struct copysign_t : eve::strict_tuple_callable<copysign_t, Options, raw_option, pedantic_option> | ||
| 21 | { | ||
| 22 | template<concepts::polyfloat_like Z1, concepts::polyfloat_like Z2> | ||
| 23 | 394 | POLYFLOAT_ABI constexpr as_polyfloat_like_t<Z1, Z2> operator()(Z1 z1, Z2 z2) const noexcept | |
| 24 | { | ||
| 25 | 394 | return POLYFLOAT_CALL(z1, z2); | |
| 26 | } | ||
| 27 | |||
| 28 | 394 | POLYFLOAT_CALLABLE_OBJECT(copysign_t, copysign_); | |
| 29 | }; | ||
| 30 | //====================================================================================================================== | ||
| 31 | //! @addtogroup core | ||
| 32 | //! @{ | ||
| 33 | //! @var copysign | ||
| 34 | //! @brief return the first parameter with the sign of the second. | ||
| 35 | //! | ||
| 36 | //! @groupheader{Header file} | ||
| 37 | //! | ||
| 38 | //! @code | ||
| 39 | //! #include <polyfloat/core.hpp> | ||
| 40 | //! @endcode | ||
| 41 | //! | ||
| 42 | //! @groupheader{Callable Signatures} | ||
| 43 | //! | ||
| 44 | //! @code | ||
| 45 | //! namespace polyfloat | ||
| 46 | //! { | ||
| 47 | //! template<polyfloat::concepts::polyfloat_like T1, polyfloat_like Z2> constexpr auto copysign(T1 z1, T2 z2) noexcept; | ||
| 48 | //! } | ||
| 49 | //! @endcode | ||
| 50 | //! | ||
| 51 | //! **Parameters** | ||
| 52 | //! | ||
| 53 | //! * `z1`, `z2`: Values to process. | ||
| 54 | //! | ||
| 55 | //! **Return value** | ||
| 56 | //! | ||
| 57 | //! Returns the z1 with the sign of z2 | ||
| 58 | //! | ||
| 59 | //! @groupheader{Example} | ||
| 60 | //! | ||
| 61 | //! @godbolt{doc/core/copysign.cpp} | ||
| 62 | //====================================================================================================================== | ||
| 63 | |||
| 64 | inline constexpr auto copysign = eve::functor<copysign_t>; | ||
| 65 | //====================================================================================================================== | ||
| 66 | //! @} | ||
| 67 | //====================================================================================================================== | ||
| 68 | } | ||
| 69 | |||
| 70 | namespace plf::_ | ||
| 71 | { | ||
| 72 | template<typename Z1, typename Z2, eve::callable_options O> | ||
| 73 | 394 | constexpr auto copysign_(POLYFLOAT_DELAY(), O const&, Z1 const& z1, Z2 const& z2) noexcept | |
| 74 | { | ||
| 75 | 394 | auto az1 = abs(z1); | |
| 76 | 394 | return plf::if_else(eve::is_positive(hi(z2)), az1, -az1); | |
| 77 | } | ||
| 78 | } | ||
| 79 |