GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/next.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 9 9 100.0%
Functions: 29 29 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 next_t : plf::elementwise_callable<next_t, eve::next_t, Options, raw_option, pedantic_option>
20 {
21 56 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
22 {
23 56 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::next] : second parameter must be positive");
31 return POLYFLOAT_CALL(z, n);
32 }
33
34 50 POLYFLOAT_CALLABLE_OBJECT(next_t, next_);
35 };
36 //======================================================================================================================
37 //! @addtogroup core
38 //! @{
39 //! @var next
40 //! @brief return the next 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 next(value auto x) noexcept; // 1
54 //! constexpr auto next(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 next nth representable value.
66 //!
67 //! @groupheader{Example}
68 //!
69 //! @godbolt{doc/core/next.cpp}
70 //======================================================================================================================
71
72 inline constexpr auto next = eve::functor<next_t>;
73 //======================================================================================================================
74 //! @}
75 //======================================================================================================================
76 }
77
78 namespace plf::_
79 {
80 50 template<typename Z, eve::callable_options O> constexpr auto next_(POLYFLOAT_DELAY(), O const&, Z const& z) noexcept
81 {
82 if constexpr (dimension_v<Z> == 2)
83 {
84 26 auto [h, l] = z;
85 26 return Z(h, eve::next(l));
86 }
87 else if constexpr (dimension_v<Z> == 3)
88 {
89 24 auto [h, m, l] = z;
90 24 auto r = Z(h, m, eve::next(l));
91 24 return if_else(plf::is_not_nan(z) && is_nan(r), inf(eve::as(r)), r);
92 }
93 }
94
95 template<typename Z, typename N, eve::callable_options O>
96 constexpr auto next_(POLYFLOAT_DELAY(), O const&, Z const& z, N n) noexcept
97 {
98 if constexpr (dimension_v<Z> == 2)
99 {
100 auto [h, l] = z;
101 return Z(h, eve::next(l, n));
102 }
103 else if constexpr (dimension_v<Z> == 3)
104 {
105 auto [h, m, l] = z;
106 auto r = Z(h, m, eve::next(l, n));
107 return if_else(plf::is_not_nan(z) && is_nan(r), inf(eve::as(r)), r);
108 }
109 }
110 }
111