GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/is_normalized.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 9 9 100.0%
Functions: 36 36 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/types/traits.hpp>
15 #include <polyfloat/module/core/parts.hpp>
16
17 namespace plf
18 {
19
20 template<typename Options>
21 struct is_normalized_t : eve::elementwise_callable<is_normalized_t, Options, raw_option, pedantic_option>
22 {
23 template<concepts::polyfloat_like Z>
24 17068502 POLYFLOAT_ABI constexpr eve::as_logical_t<plf::as_component_type_t<Z>> operator()(Z z) const noexcept
25 {
26 17068502 return POLYFLOAT_CALL(z);
27 }
28
29 17068502 POLYFLOAT_CALLABLE_OBJECT(is_normalized_t, is_normalized_);
30 };
31
32 //================================================================================================
33 //! @addtogroup core
34 //! @{
35 //! @var is_normalized
36 //! @brief returns a logical true if and only if the element value is normalized i.e. its
37 //! successive components satisfy Zhang condition of strong domination.
38 //!
39 //! @groupheader{Header file}
40 //!
41 //! @code
42 //! #include <eve/module/module/core.hpp>
43 //! @endcode
44 //!
45 //! @groupheader{Callable Signatures}
46 //!
47 //! @code
48 //! namespace plf
49 //! {
50 //! // Regular overloads
51 //! constexpr auto is_normalized(auto x) noexcept;
52 //! }
53 //! @endcode
54 //!
55 //! **Parameters**
56 //!
57 //! * `x`: [argument](@ref eve::value).
58 //!
59 //! **Return value**
60 //!
61 //! returns true if and only if x represent an normalized number.
62 //!
63 //! @note this condition is mandatory. If you want to write any function that returns a polyfloat,
64 //! the polyfloat returned MUST satisfy is_normalized.
65 //!
66 //! @groupheader{Example}
67 //! @godbolt_todo{doc/core/is_normalized.cpp}
68 //================================================================================================
69 inline constexpr auto is_normalized = eve::functor<is_normalized_t>;
70 //======================================================================================================================
71 //! @}
72 //======================================================================================================================
73 }
74
75 namespace plf::_
76 {
77 template<typename Z, eve::callable_options O>
78 17068502 constexpr auto is_normalized_(POLYFLOAT_DELAY(), O const&, Z const& z) noexcept
79 {
80 17068502 auto eqnum = eve::is_equal[eve::numeric];
81 if constexpr (plf::dimension_v<Z> == 1)
82 {
83 return eve::true_(eve::as(z));
84 }
85 else if constexpr (plf::dimension_v<Z> == 2)
86 {
87 6437774 auto [h, l] = z;
88 6437774 return eqnum(h + l, h);
89 }
90 else if constexpr (plf::dimension_v<Z> == 3)
91 {
92 10630728 auto [h, m, l] = z;
93 10630728 return eqnum(h + m, h) && eqnum(m + l, m);
94 }
95 }
96 }
97