GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/math/cot.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 23 23 100.0%
Functions: 118 130 90.8%
Branches: 4 4 100.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/math/details/sincos_coefs.hpp>
15 #include <polyfloat/module/math/details/trig_finalize.hpp>
16 #include <polyfloat/module/math/details/rempio2_limits.hpp>
17 #include <polyfloat/module/math/details/pio2_reduce.hpp>
18 #include <polyfloat/module/math/details/rem2.hpp>
19 #include <polyfloat/module/math/details/rem180.hpp>
20 #include <polyfloat/module/math/div_180.hpp>
21 #include <polyfloat/module/math/tan.hpp>
22
23 namespace plf
24 {
25
26 template<typename Options>
27 struct cot_t : plf::elementwise_callable<cot_t,
28 eve::cot_t,
29 Options,
30 raw_option,
31 pedantic_option,
32 eve::quarter_circle_option,
33 eve::half_circle_option,
34 eve::full_circle_option,
35 eve::medium_option,
36 eve::big_option,
37 eve::radpi_option,
38 eve::deg_option>
39 {
40 4122 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
41 {
42 4122 return POLYFLOAT_CALL(z);
43 }
44
45 3648 POLYFLOAT_CALLABLE_OBJECT(cot_t, cot_);
46 };
47 //======================================================================================================================
48 //! @addtogroup math
49 //! @{
50 //! @var cot
51 //! @brief return the cotangent value.
52 //!
53 //! @groupheader{Header file}
54 //!
55 //! @code
56 //! #include <polyfloat/core.hpp>
57 //! @endcode
58 //!
59 //! @groupheader{Callable Signatures}
60 //!
61 //! @code
62 //! namespace polyfloat
63 //! {
64 //! template<polyfloat::concepts::polyfloat_like T> constexpr auto cot(T z) noexcept;
65 //! }
66 //! @endcode
67 //!
68 //! **Parameters**
69 //!
70 //! * `z`: Value to process.
71 //!
72 //! **Return value**
73 //!
74 //! Returns the cotangent of z.
75 //!
76 //! @groupheader{Example}
77 //!
78 //! @godbolt{doc/math/cot.cpp}
79 //======================================================================================================================
80
81 inline constexpr auto cot = eve::functor<cot_t>;
82 //======================================================================================================================
83 //! @}
84 //======================================================================================================================
85 }
86
87 namespace plf::_
88 {
89 3648 template<typename T, eve::callable_options O> constexpr auto cot_(POLYFLOAT_DELAY(), O const&, T a0) noexcept
90 {
91 3648 auto x = abs(a0);
92 if constexpr (O::contains(eve::deg))
93 {
94 728 return plf::cot[eve::radpi](plf::div_180(a0));
95 }
96 else if constexpr (O::contains(eve::radpi))
97 {
98 if constexpr (O::contains(eve::quarter_circle))
99 {
100 768 x = plf::if_else(plf::is_not_less_equal(x, T(0.25)), plf::nan(eve::as(x)), x);
101 768 auto r = plf::rec[eve::pedantic](tancot_eval(plf::mul_pi(x)));
102 768 return plf::if_else(plf::is_negative(a0), -r, r);
103 }
104 else
105 {
106
2/2
✓ Branch 3 taken 384 times.
✓ Branch 4 taken 8 times.
784 if (eve::all(x <= T(0.25))) return plf::cot[eve::radpi][eve::quarter_circle](a0);
107 16 x = plf::if_else(plf::is_not_finite(a0) || plf::is_flint(x), plf::nan(eve::as(a0)), x);
108 48 auto [fn, xr, dxr] = plf::rem2(x);
109 16 return cot_finalize(a0, plf::quadrant(fn), xr, dxr);
110 }
111 }
112 else
113 {
114 if constexpr (O::contains(eve::quarter_circle))
115 {
116 662 auto aa0nlepio4 = is_not_less_equal(x, pio_4(eve::as<T>()));
117 662 auto r = tancot_eval(x);
118 662 r = plf::if_else(plf::is_negative(a0), -r, r);
119 662 return plf::if_else(aa0nlepio4, plf::nan(eve::as(a0)), plf::rec[eve::pedantic](r));
120 }
121 else
122 {
123
2/2
✓ Branch 5 taken 331 times.
✓ Branch 6 taken 22 times.
706 if (eve::all(x <= Rempio2_limit[eve::quarter_circle](eve::as(a0))))
124 {
125 662 return plf::cot[eve::quarter_circle](a0);
126 ;
127 }
128 else if constexpr (O::contains(eve::half_circle) || O::contains(eve::full_circle) || O::contains(eve::medium))
129 {
130 58 auto [fn, xr, dxr] = pio_2_reduce(x);
131 26 return plf::_::cot_finalize(a0, fn, xr, dxr);
132 }
133 else
134 36 return plf::cot[eve::medium](
135 36 plf::if_else(plf::is_not_less_equal(x, plf::Rempio2_limit[eve::medium](as(a0))), nan(eve::as(a0)), a0));
136 // else
137 // return cot[big](a0); TO DO REPLACE previous line
138 }
139 }
140 }
141 }
142
143 namespace plf
144 {
145 constexpr auto cotd = plf::cot[eve::deg];
146 constexpr auto cotpi = plf::cot[eve::radpi];
147 }
148