GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/minmax.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 9 9 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/abs.hpp>
15 #include <polyfloat/module/core/if_else.hpp>
16 #include <polyfloat/module/core/is_less.hpp>
17 #include <polyfloat/module/core/parts.hpp>
18
19 namespace plf
20 {
21
22 template<typename Options>
23 struct minmax_t : eve::strict_tuple_callable<minmax_t, Options, raw_option, pedantic_option>
24 {
25 template<concepts::polyfloat_like Z1, concepts::polyfloat_like... Zs>
26 8 POLYFLOAT_ABI constexpr eve::zipped<as_polyfloat_like_t<Z1, Zs...>, as_polyfloat_like_t<Z1, Zs...>> operator()(
27 Z1 z1, Zs... zs) const noexcept
28 {
29 8 return POLYFLOAT_CALL(z1, zs...);
30 }
31
32 8 POLYFLOAT_CALLABLE_OBJECT(minmax_t, minmax_);
33 };
34 //======================================================================================================================
35 //! @addtogroup core
36 //! @{
37 //! @var minmax
38 //! @brief return the minimum and maximum values.
39 //!
40 //! @groupheader{Header file}
41 //!
42 //! @code
43 //! #include <polyfloat/core.hpp>
44 //! @endcode
45 //!
46 //! @groupheader{Callable Signatures}
47 //!
48 //! @code
49 //! namespace polyfloat
50 //! {
51 //! template<polyfloat::concepts::polyfloat_like Ts...> constexpr auto minmax(Ts...zs) noexcept;
52 //! }
53 //! @endcode
54 //!
55 //! **Parameters**
56 //!
57 //! * `zs...`: Values to process.
58 //!
59 //! **Return value**
60 //!
61 //! Returns the kumi pair of the minimum and maximum value of the parameters.
62 //!
63 //! @groupheader{Example}
64 //!
65 //! @godbolt_todo{doc/core/minmax.cpp}
66 //======================================================================================================================
67
68 inline constexpr auto minmax = eve::functor<minmax_t>;
69 //======================================================================================================================
70 //! @}
71 //======================================================================================================================
72
73 }
74
75 namespace plf::_
76 {
77 template<typename Z1, typename... Zs, eve::callable_options O>
78 8 constexpr auto minmax_(POLYFLOAT_DELAY(), O const&, Z1 const& z1, Zs... zs) noexcept
79 {
80 if constexpr (sizeof...(Zs) == 0) return eve::zip(z1, z1);
81 else
82 {
83 using r_t = as_polyfloat_t<Zs...>;
84 using u_t = eve::element_type_t<r_t>;
85 8 auto cvt = [](auto a) { return plf::convert(a, as<u_t>()); };
86 if constexpr (sizeof...(Zs) == 1)
87 {
88 8 auto zz1 = cvt(z1);
89 8 auto zzs = cvt(zs...);
90 8 auto check = zz1 < zzs;
91 8 return eve::zip(plf::if_else(check, zz1, zzs), if_else(check, zzs, zz1));
92 }
93 else
94 {
95 return eve::zip(plf::min(z1, zs...), plf::max(z1, zs...));
96 }
97 }
98 }
99 }
100