GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/parts.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 8 8 100.0%
Functions: 111 111 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 template<std::ptrdiff_t Index> struct extractor
18 {
19 54630073 template<concepts::polyfloat Z> POLYFLOAT_ABI constexpr decltype(auto) operator()(Z&& z) const noexcept
20 {
21 using type = eve::element_type_t<std::remove_cvref_t<Z>>;
22 54630073 if constexpr (Index < type::static_dimension) return get<Index>(POLYFLOAT_FWD(z));
23 else return as_component_type_t<std::remove_cvref_t<Z>>{0};
24 }
25
26 14898 template<concepts::real V> POLYFLOAT_ABI constexpr decltype(auto) operator()(V&& v) const noexcept
27 {
28 using type = std::remove_cvref_t<V>;
29 14882 if constexpr (Index == 0) return POLYFLOAT_FWD(v);
30 16 else return type{0};
31 }
32 };
33
34 //====================================================================================================================
35 //! @addtogroup core
36 //! @{
37 //====================================================================================================================
38
39 //====================================================================================================================
40 //! @var hi
41 //! @brief Extracts the hi part of a value.
42 //!
43 //! @groupheader{Header file}
44 //!
45 //! @code
46 //! #include <plf/module/core.hpp>
47 //! @endcode
48 //!
49 //! @groupheader{Callable Signatures}
50 //!
51 //! @code
52 //! namespace plf
53 //! {
54 //! constexpr decltype(auto) hi(concepts::polyfloat auto&& v) noexcept; // 1
55 //! constexpr decltype(auto) hi(concepts::real auto&& v) noexcept; // 2
56 //! }
57 //! @endcode
58 //!
59 //! **Parameters**
60 //!
61 //! * `v`: Value to process.
62 //!
63 //! **Return value**
64 //!
65 //! 1. Returns a properly const-qualified reference to the hi part of `v`.
66 //! 2. Returns a properly const-qualified reference to `v`.
67 //!
68 //! @groupheader{Example}
69 //!
70 //! @godbolt_todo{doc/core/hi.cpp}
71 //====================================================================================================================
72 inline constexpr auto hi = extractor<0>{};
73
74 //====================================================================================================================
75 //! @var md
76 //! @brief Extracts the md part of a value.
77 //!
78 //! @groupheader{Header file}
79 //!
80 //! @code
81 //! #include <plf/module/core.hpp>
82 //! @endcode
83 //!
84 //! @groupheader{Callable Signatures}
85 //!
86 //! @code
87 //! namespace plf
88 //! {
89 //! constexpr decltype(auto) md(concepts::polyfloat auto&& v) noexcept; // 1
90 //! constexpr decltype(auto) md(concepts::real auto&& v) noexcept; // 2
91 //! }
92 //! @endcode
93 //!
94 //! **Parameters**
95 //!
96 //! * `v`: Value to process.
97 //!
98 //! **Return value**
99 //!
100 //! 1. Returns a properly const-qualified reference to the md part of `v`.
101 //! 2. Returns a properly const-qualified reference to `v`.
102 //!
103 //! @note the md part of a floating point value is always 0, for polyfloat the md part
104 //! always refers to the second component.
105 //!
106 //! @groupheader{Example}
107 //!
108 //! @godbolt_todo{doc/core/md.cpp}
109 //====================================================================================================================
110 inline constexpr auto md = extractor<1>{};
111
112 //====================================================================================================================
113 //! @var lo
114 //! @brief Extracts the lo part of a value.
115 //!
116 //! @groupheader{Header file}
117 //!
118 //! @code
119 //! #include <plf/module/core.hpp>
120 //! @endcode
121 //!
122 //! @groupheader{Callable Signatures}
123 //!
124 //! @code
125 //! namespace plf
126 //! {
127 //! constexpr decltype(auto) lo(concepts::polyfloat auto&& v) noexcept; // 1
128 //! constexpr decltype(auto) lo(concepts::real auto&& v) noexcept; // 2
129 //! }
130 //! @endcode
131 //!
132 //! **Parameters**
133 //!
134 //! * `v`: Value to process.
135 //!
136 //! **Return value**
137 //!
138 //! 1. Returns a properly const-qualified reference to the lo part of `v`.
139 //! 2. Returns a properly const-qualified reference to `v`.
140 //!
141 //! @note the lo part of a floating point value is always 0, for polyfloat the lo part
142 //! always refers to the last component.
143 //!
144 //! @groupheader{Example}
145 //!
146 //! @godbolt_todo{doc/core/lo.cpp}
147 //====================================================================================================================
148
149 // TODO
150 template<typename Options> struct lo_t : eve::elementwise_callable<lo_t, Options, raw_option, pedantic_option>
151 {
152 19452445 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr decltype(auto) operator()(Z&& z) const noexcept
153 {
154 8 if constexpr (dimension_v<Z> == 1) return extractor<1>{}(z);
155 19452437 else return extractor<dimension_v<Z> - 1>{}(z);
156 }
157
158 POLYFLOAT_CALLABLE_OBJECT(lo_t, lo_);
159 };
160 inline constexpr auto lo = eve::functor<lo_t>;
161
162 }
163