GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/prev.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 8 8 100.0%
Functions: 41 41 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
15 namespace plf
16 {
17
18 template<typename Options>
19 struct prev_t : plf::elementwise_callable<prev_t, eve::prev_t, Options, raw_option, pedantic_option>
20 {
21 3762 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
22 {
23 3762 return POLYFLOAT_CALL(z);
24 }
25
26 template<concepts::polyfloat_like Z, eve::integral_value N>
27 POLYFLOAT_ABI constexpr Z operator()(Z z, N n) const noexcept
28 requires(eve::same_lanes_or_scalar<Z, N>)
29 {
30 EVE_ASSERT(eve::all(n >= 0), "[plf::prev] : second parameter must be positive");
31 return POLYFLOAT_CALL(z, n);
32 }
33
34 3756 POLYFLOAT_CALLABLE_OBJECT(prev_t, prev_);
35 };
36 //======================================================================================================================
37 //! @addtogroup core
38 //! @{
39 //! @var prev
40 //! @brief return the previous representable value.
41 //!
42 //! @groupheader{Header file}
43 //!
44 //! @code
45 //! #include <polyfloat/module/core.hpp>
46 //! @endcode
47 //!
48 //! @groupheader{Callable Signatures}
49 //!
50 //! @code
51 //! namespace polyfloat
52 //! {
53 //! constexpr auto prev(value auto x) noexcept; // 1
54 //! constexpr auto prev(value auto x, integral_value auto n) noexcept; // 2
55 //! }
56 //! @endcode
57 //!
58 //! **Parameters**
59 //!
60 //! * `z`: Value to process.
61 //! * `n`: increment
62 //!
63 //! **Return value**
64 //!
65 //! Returns the previous nth representable value.
66 //!
67 //! @groupheader{Example}
68 //!
69 //! @godbolt{doc/core/prev.cpp}
70 //======================================================================================================================
71
72 inline constexpr auto prev = eve::functor<prev_t>;
73 //======================================================================================================================
74 //! @}
75 //======================================================================================================================
76 }
77
78 namespace plf::_
79 {
80 3756 template<typename Z, eve::callable_options O> constexpr auto prev_(POLYFLOAT_DELAY(), O const&, Z const& z) noexcept
81 {
82 using c_t = plf::as_component_type_t<Z>;
83 if constexpr (dimension_v<Z> == 2)
84 {
85 198 auto [h, l] = z;
86 198 return plf::_::from_pair<c_t>(h, eve::prev(l));
87 }
88 else if constexpr (dimension_v<Z> == 3)
89 {
90 3558 auto [h, m, l] = z;
91 3558 return plf::_::from_triple<c_t>(h, m, eve::prev(l));
92 }
93 }
94
95 template<typename Z, typename N, eve::callable_options O>
96 constexpr auto prev_(POLYFLOAT_DELAY(), O const&, Z const& z, N n) noexcept
97 {
98 using c_t = plf::as_component_type_t<Z>;
99 if constexpr (dimension_v<Z> == 2)
100 {
101 auto [h, l] = z;
102 return plf::_::from_pair<c_t>(h, eve::prev(l, n));
103 }
104 else if constexpr (dimension_v<Z> == 3)
105 {
106 auto [h, m, l] = z;
107 return plf::_::from_triple<c_t>(h, m, eve::prev(l, n));
108 }
109 }
110 }
111