GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/math/tan.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 17 21 81.0%
Functions: 100 100 100.0%
Branches: 1 6 16.7%

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/trig_finalize.hpp>
15 #include <polyfloat/module/math/details/rempio2_limits.hpp>
16 #include <polyfloat/module/math/details/pio2_reduce.hpp>
17 #include <polyfloat/module/math/details/rem2.hpp>
18 #include <polyfloat/module/math/details/rem180.hpp>
19 #include <polyfloat/module/math/mul_pi.hpp>
20 #include <polyfloat/module/math/div_180.hpp>
21 #include <iostream>
22
23 namespace plf
24 {
25
26 template<typename Options>
27 struct tan_t : plf::elementwise_callable<tan_t,
28 eve::tan_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 81206 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
41 {
42 81206 return POLYFLOAT_CALL(z);
43 }
44
45 80736 POLYFLOAT_CALLABLE_OBJECT(tan_t, tan_);
46 };
47 //======================================================================================================================
48 //! @addtogroup math
49 //! @{
50 //! @var tan
51 //! @brief return the tangent 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 tan(T z) noexcept;
65 //! }
66 //! @endcode
67 //!
68 //! **Parameters**
69 //!
70 //! * `z`: Value to process.
71 //!
72 //! **Return value**
73 //!
74 //! Returns the tangent of z.
75 //!
76 //! @groupheader{Example}
77 //!
78 //! @godbolt{doc/math/tan.cpp}
79 //======================================================================================================================
80
81 inline constexpr auto tan = eve::functor<tan_t>;
82 //======================================================================================================================
83 //! @}
84 //======================================================================================================================
85 }
86
87 namespace plf::_
88 {
89 80736 template<typename T, eve::callable_options O> constexpr auto tan_(POLYFLOAT_DELAY(), O const&, T a0) noexcept
90 {
91 if constexpr (O::contains(eve::deg))
92 {
93 736 return plf::tan[eve::radpi](plf::div_180(a0));
94 }
95 else if constexpr (O::contains(eve::radpi))
96 {
97 if constexpr (O::contains(eve::quarter_circle))
98 {
99 return plf::tan[eve::quarter_circle](plf::mul_pi(a0));
100 }
101 else
102 {
103 800 auto x = plf::abs(a0);
104 800 x = plf::if_else(plf::is_not_finite(x), plf::nan(eve::as(x)), x); // nan or Inf input
105 800 x = plf::if_else(plf::is_greater(x, plf::maxflint(eve::as(x))), eve::zero,
106 x); //over maxflint all inputs are even integers
107 2400 auto [fn, xr, dxr] = plf::rem2(x);
108 800 return tan_finalize(a0, fn, xr, dxr);
109 }
110 }
111 else
112 {
113 79200 auto x = plf::abs(a0);
114 if constexpr (O::contains(eve::quarter_circle))
115 {
116 75628 auto r = tancot_eval(x);
117 75628 return plf::if_else(plf::is_negative(a0), -r, r);
118 }
119 else if constexpr (O::contains(eve::half_circle) || O::contains(eve::full_circle) || O::contains(eve::medium))
120 {
121 2148 auto [fn, xr, dxr] = pio_2_reduce(x);
122 716 return plf::_::tan_finalize(a0, fn, xr, dxr);
123 }
124 else
125 {
126
1/2
✓ Branch 5 taken 1428 times.
✗ Branch 6 not taken.
2856 if (eve::all(x <= Rempio2_limit[eve::quarter_circle](eve::as(a0))))
127 {
128 2856 return plf::tan[eve::quarter_circle](a0);
129 }
130 ✗ else if (eve::all(x <= Rempio2_limit[quarter_circle](as(a0)))) return tan[quarter_circle](a0);
131 ✗ else if (eve::all(x <= Rempio2_limit[medium](as(a0)))) return tan[medium](a0);
132 else
133 ✗ return plf::tan[eve::medium](
134 ✗ plf::if_else(is_not_less_equal(x, Rempio2_limit[medium](as(a0))), nan(eve::as(a0)), tan[medium](a0)));
135 //else return tan[big](a0); TO DO REPLACE previous line
136 }
137 }
138 }
139 }
140
141 namespace plf
142 {
143 constexpr auto tand = plf::tan[eve::deg];
144 constexpr auto tanpi = plf::tan[eve::radpi];
145 }
146