GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/quadrant.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/module/core/trunc.hpp>
15 #include <polyfloat/module/core/floor.hpp>
16
17 namespace plf
18 {
19
20 template<typename Options>
21 struct quadrant_t : eve::elementwise_callable<quadrant_t, Options, raw_option, pedantic_option>
22 {
23 template<concepts::polyfloat_like Z>
24 2289 POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
25 requires(!eve::integral_value<Z>)
26 {
27 2289 return POLYFLOAT_CALL(z);
28 }
29
30 88 template<eve::integral_value Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
31 {
32 88 return POLYFLOAT_CALL(z);
33 }
34 2462 POLYFLOAT_CALLABLE_OBJECT(quadrant_t, quadrant_);
35 };
36 //======================================================================================================================
37 //! @addtogroup core
38 //! @{
39 //! @var quadrant
40 //! @brief return the quadrant value.
41 //!
42 //! @groupheader{Header file}
43 //!
44 //! @code
45 //! #include <polyfloat/core.hpp>
46 //! @endcode
47 //!
48 //! @groupheader{Callable Signatures}
49 //!
50 //! @code
51 //! namespace polyfloat
52 //! {
53 //! template<polyfloat::concepts::polyfloat_like T> constexpr auto quadrant(T n) noexcept;
54 //! }
55 //! @endcode
56 //!
57 //! **Parameters**
58 //!
59 //! * `n`: Value to process. Must be of integral type or a [flint](@ref is_flint)
60 //!
61 //! **Return value**
62 //!
63 //! return a value of the same type as `n` containing the quadrant number where `n` (supposed an
64 //! integer) lies.
65 //!
66 //! @groupheader{Example}
67 //!
68 //! @godbolt{doc/core/quadrant.cpp}
69 //======================================================================================================================
70
71 inline constexpr auto quadrant = eve::functor<quadrant_t>;
72 //======================================================================================================================
73 //! @}
74 //======================================================================================================================
75 }
76
77 namespace plf::_
78 {
79 template<typename Z, eve::callable_options O>
80 2462 constexpr auto quadrant_(POLYFLOAT_DELAY(), O const&, Z const& a) noexcept
81 {
82 172 if constexpr (eve::integral_value<Z>) return a & Z(3);
83 else
84 {
85 2290 Z b = plf::trunc(a) / 4;
86 2290 return (b - plf::floor(b)) * 4;
87 }
88 }
89 }
90