GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/sign_alternate.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 4 4 100.0%
Functions: 12 12 100.0%
Branches: 0 0 -%

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/trunc.hpp>
15 #include <polyfloat/module/core/nearest.hpp>
16 #include <polyfloat/module/core/ceil.hpp>
17 #include <polyfloat/module/core/floor.hpp>
18
19 namespace plf
20 {
21
22 template<typename Options>
23 struct sign_alternate_t : eve::callable<sign_alternate_t,
24 Options,
25 raw_option,
26 pedantic_option,
27 to_nearest_option,
28 toward_zero_option,
29 downward_option,
30 upward_option>
31 {
32 8 template<concepts::polyfloat_like Z> POLYFLOAT_ABI Z operator()(Z z) const noexcept { return POLYFLOAT_CALL(z); }
33
34 8 POLYFLOAT_CALLABLE_OBJECT(sign_alternate_t, sign_alternate_);
35 };
36 //======================================================================================================================
37 //! @addtogroup core
38 //! @{
39 //! @var sign_alternate
40 //! @brief return the sign_alternateender after division of the values.
41 //!
42 //! @groupheader{Header file}
43 //!
44 //! @code
45 //! #include <polyfloat/core.hpp>
46 //! @endcode
47 //!
48 //! @groupheader{Callable Signatures}
49 //!
50 //! @code
51 //! namespace polyfloat
52 //! {
53 //! template<polyfloat::concepts::polyfloat_like T1, polyfloat_like T2> constexpr auto sign_alternate(T1 x, T2 y) noexcept; //1
54 //!
55 //! // Semantic exclusive options
56 //! constexpr auto sign_alternate[upward](/*any of the above overloads*/) noexcept; // 2
57 //! constexpr auto sign_alternate[downward](/*any of the above overloads*/) noexcept; // 2
58 //! constexpr auto sign_alternate[toward_zero](/*any of the above overloads*/) noexcept; // 2
59 //! constexpr auto sign_alternate[to_nearest](/*any of the above overloads*/) noexcept; // 2
60 //! }
61 //! @endcode
62 //!
63 //! **Parameters**
64 //!
65 //! * `z1`: Value to process.
66 //!
67 //! **Return value**
68 //!
69 //! 1. Return \f$(-1)^\tilde n\f$ is returned, where \f$\tilde n\f$ is the truncation of `n`.
70 //! 2. The chosen rounding option is applyied to `n` before computation, instead of truncation.
71 //!
72 //!
73 //! @groupheader{Example}
74 //!
75 //! @godbolt_todo{doc/core/sign_alternate.cpp}
76 //======================================================================================================================
77
78 inline constexpr auto sign_alternate = eve::functor<sign_alternate_t>;
79 //======================================================================================================================
80 //! @}
81 //======================================================================================================================
82 }
83
84 namespace plf::_
85 {
86 template<typename T, eve::callable_options O>
87 8 constexpr auto sign_alternate_(POLYFLOAT_DELAY(), O const& o, T n) noexcept
88 {
89 if constexpr (O::contains_any(upward, downward, to_nearest, toward_zero))
90 return plf::if_else(is_odd(plf::round[o](n)), eve::mone, plf::one(as(n)));
91 8 else return plf::if_else(is_odd(plf::trunc(n)), eve::mone, plf::one(as(n)));
92 }
93 }
94