| 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/fma.hpp> | ||
| 15 | #include <polyfloat/module/core/nearest.hpp> | ||
| 16 | #include <polyfloat/module/core/quadrant.hpp> | ||
| 17 | #include <eve/traits/helpers.hpp> | ||
| 18 | #include <polyfloat/module/core/two_fma_approx.hpp> | ||
| 19 | |||
| 20 | namespace plf | ||
| 21 | { | ||
| 22 | template<typename Options> struct rem2_t : eve::elementwise_callable<rem2_t, Options, pedantic_option, raw_option> | ||
| 23 | { | ||
| 24 | 984 | template<concepts::polyfloat_like T> POLYFLOAT_ABI constexpr eve::zipped<T, T, T> operator()(T v) const | |
| 25 | { | ||
| 26 | 984 | return POLYFLOAT_CALL(v); | |
| 27 | } | ||
| 28 | |||
| 29 | 984 | POLYFLOAT_CALLABLE_OBJECT(rem2_t, rem2_); | |
| 30 | }; | ||
| 31 | |||
| 32 | inline constexpr auto rem2 = eve::functor<rem2_t>; | ||
| 33 | } | ||
| 34 | |||
| 35 | namespace plf::_ | ||
| 36 | { | ||
| 37 | 984 | template<typename T, eve::callable_options O> constexpr auto rem2_(POLYFLOAT_DELAY(), O const&, T x) noexcept | |
| 38 | { | ||
| 39 | 984 | auto xi = plf::nearest(x + x); | |
| 40 | if constexpr (O::contains(eve::pedantic)) | ||
| 41 | { | ||
| 42 | auto [x_2, dx_2] = plf::two_fma_approx(xi, plf::mhalf(eve::as<T>()), x); | ||
| 43 | auto xr = x_2 * pi(eve::as<T>()); | ||
| 44 | auto dxr = dx_2 * pi(eve::as<T>()); | ||
| 45 | return eve::zip(plf::quadrant(xi), xr, dxr); | ||
| 46 | } | ||
| 47 | else | ||
| 48 | { | ||
| 49 | 984 | auto x_2 = plf::fma(xi, plf::mhalf(eve::as<T>()), x); | |
| 50 | 984 | auto xr = x_2 * pi(eve::as<T>()); | |
| 51 | 984 | auto dxr = plf::zero(eve::as(xr)); | |
| 52 | 984 | return eve::zip(plf::quadrant(xi), xr, dxr); | |
| 53 | } | ||
| 54 | } | ||
| 55 | } | ||
| 56 |