GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/epsilon.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 13 13 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/minus.hpp>
15 #include <polyfloat/module/core/is_negative.hpp>
16
17 namespace plf
18 {
19
20 template<typename Options>
21 struct epsilon_t : plf::elementwise_callable<epsilon_t, eve::epsilon_t, Options, raw_option, pedantic_option>
22 {
23 18 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr as_component_type_t<Z> operator()(Z z) const noexcept
24 {
25 18 return POLYFLOAT_CALL(z);
26 }
27
28 16 POLYFLOAT_CALLABLE_OBJECT(epsilon_t, epsilon_);
29 };
30 //======================================================================================================================
31 //! @addtogroup core
32 //! @{
33 //! @var epsilon
34 //! @brief return the epsilon value.
35 //!
36 //! @groupheader{Header file}
37 //!
38 //! @code
39 //! #include <polyfloat/core.hpp>
40 //! @endcode
41 //!
42 //! @groupheader{Callable Signatures}
43 //!
44 //! @code
45 //! namespace polyfloat
46 //! {
47 //! template<polyfloat::concepts::polyfloat_like T> constexpr auto epsilon(T z) noexcept;
48 //! }
49 //! @endcode
50 //!
51 //! **Parameters**
52 //!
53 //! * `z`: Value to process.
54 //!
55 //! **Return value**
56 //!
57 //! Returns the epsilon of z.
58 //!
59 //! @groupheader{Example}
60 //!
61 //! @godbolt{doc/core/epsilon.cpp}
62 //======================================================================================================================
63
64 inline constexpr auto epsilon = eve::functor<epsilon_t>;
65 //======================================================================================================================
66 //! @}
67 //======================================================================================================================
68 }
69
70 namespace plf::_
71 {
72 template<typename Z, eve::callable_options O>
73 16 constexpr auto epsilon_(POLYFLOAT_DELAY(), O const&, Z const& z) noexcept
74 {
75 if constexpr (dimension_v<Z> == 2)
76 {
77 8 auto [h, l] = z;
78 8 return if_else(eve::is_nez(l), eve::epsilon(l), eve::epsilon(eve::sulp(h)));
79 }
80 else if constexpr (dimension_v<Z> == 3)
81 {
82 8 auto [h, m, l] = z;
83 8 return plf::if_else(
84 8 eve::is_nez(l), eve::epsilon(l),
85 16 plf::if_else(eve::is_nez(m), eve::epsilon(eve::sulp(m)), eve::epsilon(eve::sulp(eve::sulp(h)))));
86 }
87 }
88 }
89