GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/max.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 11 11 100.0%
Functions: 122 122 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 max_t : eve::callable<max_t, Options, raw_option, pedantic_option>
23 {
24 template<concepts::polyfloat_like Z1, concepts::polyfloat_like... Zs>
25 139628 POLYFLOAT_ABI constexpr as_polyfloat_like_t<Z1, Zs...> operator()(Z1 z1, Zs... zs) const noexcept
26 {
27 139628 return POLYFLOAT_CALL(z1, zs...);
28 }
29
30 139628 POLYFLOAT_CALLABLE_OBJECT(max_t, max_);
31 };
32 //======================================================================================================================
33 //! @addtogroup core
34 //! @{
35 //! @var max
36 //! @brief return the maximum 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 max(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 maximum value of the parameters.
60 //!
61 //! @groupheader{Example}
62 //!
63 //! @godbolt{doc/core/max.cpp}
64 //======================================================================================================================
65
66 inline constexpr auto max = eve::functor<max_t>;
67 //======================================================================================================================
68 //! @}
69 //======================================================================================================================
70
71 35 template<typename Options> constexpr auto neutral(max_t<Options>) noexcept
72 {
73 35 return plf::valmin;
74 }
75 }
76
77 namespace plf::_
78 {
79 template<typename Z1, eve::callable_options O> constexpr auto max_(POLYFLOAT_DELAY(), O const&, Z1 z1) noexcept
80 {
81 return z1;
82 }
83
84 template<typename Z0, typename Z1, typename... Zs, eve::callable_options O>
85 139628 constexpr auto max_(POLYFLOAT_DELAY(), O const&, Z0 z0, Z1 z1, Zs... zs) noexcept
86 {
87 using r_t = as_polyfloat_t<Z0, Z1, Zs...>;
88 using u_t = eve::element_type_t<r_t>;
89 232876 auto cvt = [](auto a) { return plf::convert(a, as<u_t>()); };
90 if constexpr (sizeof...(Zs) == 0)
91 {
92 93244 return plf::if_else(plf::is_less(cvt(z0), cvt(z1)), cvt(z1), cvt(z0));
93 }
94 else
95 {
96 46384 r_t that = max(cvt(z0), cvt(z1));
97 46384 ((that = max(that, zs)), ...);
98 46384 return that;
99 }
100 }
101 }
102