GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/min.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 9 9 100.0%
Functions: 75 75 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> struct min_t : eve::strict_tuple_callable<min_t, Options, raw_option, pedantic_option>
23 {
24 template<concepts::polyfloat_like Z1, concepts::polyfloat_like... Zs>
25 242 POLYFLOAT_ABI constexpr as_polyfloat_like_t<Z1, Zs...> operator()(Z1 z1, Zs... zs) const noexcept
26 {
27 242 return POLYFLOAT_CALL(z1, zs...);
28 }
29
30 242 POLYFLOAT_CALLABLE_OBJECT(min_t, min_);
31 };
32 //======================================================================================================================
33 //! @addtogroup core
34 //! @{
35 //! @var min
36 //! @brief return the minimum value.
37 //!
38 //! @groupheader{Header file}
39 //!
40 //! @code
41 //! #include <polyfloat/core.hpp>
42 //! @endcode
43 //!
44 //! @groupheader{Callable Signatures}
45 //!
46 //! @code
47 //! namespace polyfloat
48 //! {
49 //! template<polyfloat::concepts::polyfloat_like T1, polyfloat_like Z2> constexpr auto min(T1 z1, T2 z2) noexcept;
50 //! }
51 //! @endcode
52 //!
53 //! **Parameters**
54 //!
55 //! * `z, zs...`: Values to process.
56 //!
57 //! **Return value**
58 //!
59 //! Returns the minimum value of the parameters.
60 //!
61 //! @groupheader{Example}
62 //!
63 //! @godbolt{doc/core/min.cpp}
64 //======================================================================================================================
65
66 inline constexpr auto min = eve::functor<min_t>;
67 //======================================================================================================================
68 //! @}
69 //======================================================================================================================
70
71 template<typename Options> constexpr auto neutral(min_t<Options>) noexcept
72 {
73 return plf::valmax;
74 }
75 }
76
77 namespace plf::_
78 {
79 template<typename Z1, typename... Zs, eve::callable_options O>
80 242 constexpr auto min_(POLYFLOAT_DELAY(), O const&, Z1 z1, Zs... zs) noexcept
81 {
82 using r_t = as_polyfloat_t<Z1, Zs...>;
83 using u_t = eve::element_type_t<r_t>;
84 241 auto cvt = [](auto a) { return plf::convert(a, as<u_t>()); };
85 240 if constexpr (sizeof...(Zs) == 1) return plf::if_else(plf::is_less(z1, zs...), cvt(z1), cvt(zs)...);
86 else
87 {
88 2 r_t that(cvt(z1));
89 2 ((that = min(that, zs)), ...);
90 2 return that;
91 }
92 }
93 }
94