GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/types/ops1.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 341 349 97.7%
Branches: 51 54 94.4%

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 #include <eve/eve.hpp>
10 #include <polyfloat/module/core/parts.hpp>
11 #include <polyfloat/module/core/convert.hpp>
12
13 namespace plf
14 {
15 //====================================================================================================================
16 //! @name Unary Operators
17 //! @{
18 //====================================================================================================================
19
20 //! @brief Identity for polyfloat value
21 //! @related polyfloat
22 template<concepts::polyfloat Z> constexpr auto operator+(Z const& z) noexcept
23 {
24 return z;
25 }
26
27 //! @brief Compute the opposite of a given poly float value
28 //! @related polyfloat
29 5540281 template<concepts::polyfloat Z> constexpr auto operator-(Z const& z) noexcept
30 {
31 13009085 return Z{kumi::map([](auto m) { return -m; }, z)};
32 }
33
34 //====================================================================================================================
35 //! @}
36 //====================================================================================================================
37
38 //====================================================================================================================
39 //! @name Binary Operators + - == !=
40 //! @{
41 //====================================================================================================================
42
43 //! @brief Returns the sum of two poly float values
44 //! @related polyfloat
45 template<eve::value T1, eve::value T2>
46 requires(concepts::polyfloat<T1> || concepts::polyfloat<T2>)
47 3608698 as_polyfloat_t<T1, T2> operator+(T1 const& a, T2 const& b) noexcept
48 {
49 using type = as_polyfloat_t<T1, T2>;
50 3608698 type that{plf::convert(a, eve::as<eve::element_type_t<type>>())};
51 3608698 return that += b;
52 }
53
54 //! @brief Returns the difference of a poly float and a floating point value
55 //! @related polyfloat
56 template<eve::value T1, eve::value T2>
57 requires(concepts::polyfloat<T1> || concepts::polyfloat<T2>)
58 4845808 as_polyfloat_t<T1, T2> operator-(T1 const& a, T2 const& b) noexcept
59 {
60 using type = as_polyfloat_t<T1, T2>;
61 4845808 type that{plf::convert(a, eve::as<eve::element_type_t<type>>())};
62 4845808 return that -= b;
63 }
64
65 //! @brief Returns the product of two poly float values
66 //! @related polyfloat
67 template<eve::value T1, eve::value T2>
68 requires(concepts::polyfloat<T1> || concepts::polyfloat<T2>)
69 6961632 as_polyfloat_t<T1, T2> operator*(T1 const& a, T2 const& b) noexcept
70 {
71 using type = as_polyfloat_t<T1, T2>;
72 6961632 type that{plf::convert(a, eve::as<eve::element_type_t<type>>())};
73 6961632 return that *= b;
74 }
75
76 //! @brief Compares two polyfloat_like for equality
77 //! @related polyfloat
78 29698 template<concepts::polyfloat_like T1, concepts::polyfloat_like T2> constexpr auto operator==(T1 const& a, T2 b)
79 {
80 using r_t = eve::common_logical_t<as_component_type_t<T1>, as_component_type_t<T2>>;
81 178 if constexpr (dimension_v<T1> > dimension_v<T2>) return b == a;
82 else if constexpr (dimension_v<T1> == 1)
83 {
84 if constexpr (dimension_v<T2> == 1) return r_t(a == b);
85 198 else if constexpr (dimension_v<T2> >= 2) return r_t(a == hi(b)) && eve::is_eqz(md(b));
86 }
87 else if constexpr (dimension_v<T1> == 2)
88 {
89
4/4
✓ Branch 2 taken 890 times.
✓ Branch 3 taken 1546 times.
✓ Branch 6 taken 885 times.
✓ Branch 7 taken 5 times.
4871 if constexpr (dimension_v<T2> == 2) return r_t((hi(a) == hi(b)) && (md(a) == md(b)));
90 18 else if constexpr (dimension_v<T2> == 3) return r_t((hi(a) == b) && (md(a) == md(b)) && eve::is_eqz(lo(b)));
91 }
92
5/6
✓ Branch 2 taken 4837 times.
✓ Branch 3 taken 7439 times.
✓ Branch 6 taken 4761 times.
✓ Branch 7 taken 76 times.
✓ Branch 10 taken 4761 times.
✗ Branch 11 not taken.
24433 else if constexpr (dimension_v<T1> == 3) return r_t((hi(a) == hi(b)) && (md(a) == md(b)) && (lo(a) == lo(b)));
93 }
94
95 //! @brief Compares two polyfloat_like for inequality
96 //! @related polyfloat
97 105886 template<concepts::polyfloat_like T1, concepts::polyfloat_like T2> constexpr auto operator!=(T1 const& a, T2 b)
98 {
99 using r_t = eve::common_logical_t<as_component_type_t<T1>, as_component_type_t<T2>>;
100 6 if constexpr (dimension_v<T1> > dimension_v<T2>) return b != a;
101 else if constexpr (dimension_v<T1> == 1) //now dimension_v<T1> <= dimension_v<T2>
102 {
103 if constexpr (dimension_v<T2> == 1) return r_t(a != b);
104 10 else if constexpr (dimension_v<T2> >= 2) return r_t(a != hi(b)) || eve::is_nez(md(b));
105 }
106 else if constexpr (dimension_v<T1> == 2)
107 {
108
4/4
✓ Branch 2 taken 1032 times.
✓ Branch 3 taken 7485 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 1024 times.
17025 if constexpr (dimension_v<T2> == 2) return r_t((hi(a) != hi(b)) || (md(a) != md(b)));
109 6 else if constexpr (dimension_v<T2> == 3) return r_t((hi(a) != b) || (md(a) != md(b)) || eve::is_nez(lo(b)));
110 }
111
6/6
✓ Branch 2 taken 6365 times.
✓ Branch 3 taken 38571 times.
✓ Branch 6 taken 6087 times.
✓ Branch 7 taken 278 times.
✓ Branch 10 taken 2254 times.
✓ Branch 11 taken 3833 times.
88839 else if constexpr (dimension_v<T1> == 3) return r_t((hi(a) != hi(b)) || (md(a) != md(b)) || (lo(a) != lo(b)));
112 }
113
114 //====================================================================================================================
115 //! @}
116 //====================================================================================================================
117
118 //====================================================================================================================
119 //! @name Binary Operators < > <= >=
120 //! @{
121 //====================================================================================================================
122
123 template<eve::value T1, eve::value T2>
124 requires(concepts::polyfloat<T1> || concepts::polyfloat<T2>)
125 172618 auto operator<(T1 const& a, T2 const& b) noexcept
126 {
127 using r_t = eve::common_logical_t<as_component_type_t<T1>, as_component_type_t<T2>>;
128 using type = as_polyfloat_t<T1, T2>;
129 172618 auto aa{plf::convert(a, eve::as<eve::element_type_t<type>>())};
130 172618 auto bb{plf::convert(b, eve::as<eve::element_type_t<type>>())};
131 if constexpr (dimension_v<type> == 1) return r_t(aa < bb);
132 else if constexpr (dimension_v<type> == 2)
133 {
134
4/4
✓ Branch 5 taken 2735 times.
✓ Branch 6 taken 5949 times.
✓ Branch 9 taken 839 times.
✓ Branch 10 taken 1896 times.
17370 return r_t(hi(aa) < hi(bb)) || ((hi(aa) == hi(bb)) && (lo(aa) < lo(bb)));
135 }
136 else if constexpr (dimension_v<type> == 3)
137 {
138
6/6
✓ Branch 2 taken 35839 times.
✓ Branch 3 taken 41897 times.
✓ Branch 6 taken 20577 times.
✓ Branch 7 taken 15262 times.
✓ Branch 10 taken 20568 times.
✓ Branch 11 taken 9 times.
226802 return r_t((hi(aa) < hi(bb)) || ((hi(aa) == hi(bb)) && (md(aa) < md(bb))) ||
139
6/6
✓ Branch 2 taken 20568 times.
✓ Branch 3 taken 15262 times.
✓ Branch 6 taken 20550 times.
✓ Branch 7 taken 18 times.
✓ Branch 10 taken 8302 times.
✓ Branch 11 taken 12248 times.
226802 ((hi(aa) == hi(bb)) && (md(aa) == md(bb)) && (lo(aa) < lo(bb))));
140 }
141 }
142
143 template<eve::value T1, eve::value T2>
144 requires(concepts::polyfloat<T1> || concepts::polyfloat<T2>)
145 87082 eve::as_logical_t<as_polyfloat_t<T1, T2>> operator>(T1 const& a, T2 const& b) noexcept
146 {
147 using type = as_polyfloat_t<T1, T2>;
148 87082 auto aa{plf::convert(a, eve::as<eve::element_type_t<type>>())};
149 87082 auto bb{plf::convert(b, eve::as<eve::element_type_t<type>>())};
150 if constexpr (dimension_v<type> == 1) return aa > bb;
151 else if constexpr (dimension_v<type> == 2)
152 {
153
6/6
✓ Branch 2 taken 3415 times.
✓ Branch 3 taken 1617 times.
✓ Branch 6 taken 65 times.
✓ Branch 7 taken 3350 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 61 times.
10083 return (hi(aa) > hi(bb)) || ((hi(aa) == hi(bb)) && (lo(aa) > lo(bb)));
154 }
155 else if constexpr (dimension_v<type> == 3)
156 {
157
5/6
✓ Branch 2 taken 19289 times.
✓ Branch 3 taken 19207 times.
✓ Branch 6 taken 56 times.
✓ Branch 7 taken 19233 times.
✓ Branch 10 taken 56 times.
✗ Branch 11 not taken.
115584 return ((hi(aa) > hi(bb)) || ((hi(aa) == hi(bb)) && (md(aa) > md(bb))) ||
158
5/6
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 19233 times.
✓ Branch 6 taken 56 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 54 times.
115584 ((hi(aa) == hi(bb)) && (md(aa) == md(bb)) && (lo(aa) > lo(bb))));
159 }
160 }
161
162 template<eve::value T1, eve::value T2>
163 requires(concepts::polyfloat<T1> || concepts::polyfloat<T2>)
164 4418 eve::as_logical_t<as_polyfloat_t<T1, T2>> operator<=(T1 const& a, T2 const& b) noexcept
165 {
166 4418 return (a < b) || (a == b);
167 }
168
169 template<eve::value T1, eve::value T2>
170 requires(concepts::polyfloat<T1> || concepts::polyfloat<T2>)
171 2272 eve::as_logical_t<as_polyfloat_t<T1, T2>> operator>=(T1 const& a, T2 const& b) noexcept
172 {
173 2272 return (a > b) || (a == b);
174 }
175 }
176