GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/math/csc.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 5 5 100.0%
Functions: 40 40 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/math/sin.hpp>
15
16 namespace plf
17 {
18
19 template<typename Options>
20 struct csc_t : plf::elementwise_callable<csc_t,
21 eve::csc_t,
22 Options,
23 raw_option,
24 pedantic_option,
25 eve::quarter_circle_option,
26 eve::half_circle_option,
27 eve::full_circle_option,
28 eve::medium_option,
29 eve::big_option,
30 eve::radpi_option,
31 eve::deg_option>
32 {
33 104 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
34 {
35 104 return POLYFLOAT_CALL(z);
36 }
37
38 94 POLYFLOAT_CALLABLE_OBJECT(csc_t, csc_);
39 };
40 //======================================================================================================================
41 //! @addtogroup math
42 //! @{
43 //! @var csc
44 //! @brief return the cosecant value.
45 //!
46 //! @groupheader{Header file}
47 //!
48 //! @code
49 //! #include <polyfloat/core.hpp>
50 //! @endcode
51 //!
52 //! @groupheader{Callable Signatures}
53 //!
54 //! @code
55 //! namespace polyfloat
56 //! {
57 //! template<polyfloat::concepts::polyfloat_like T> constexpr auto csc(T z) noexcept;
58 //! }
59 //! @endcode
60 //!
61 //! **Parameters**
62 //!
63 //! * `z`: Value to process.
64 //!
65 //! **Return value**
66 //!
67 //! Returns the cosecant of z.
68 //!
69 //! @groupheader{Example}
70 //!
71 //! @godbolt{doc/math/csc.cpp}
72 //======================================================================================================================
73
74 inline constexpr auto csc = eve::functor<csc_t>;
75 //======================================================================================================================
76 //! @}
77 //======================================================================================================================
78 }
79
80 namespace plf::_
81 {
82 94 template<typename T, eve::callable_options O> constexpr auto csc_(POLYFLOAT_DELAY(), O const& o, T a0) noexcept
83 {
84 if constexpr (O::contains(eve::radpi))
85 {
86 T x = plf::abs(a0);
87 x = plf::if_else(plf::is_nez(a0) && (plf::is_not_finite(x) || plf::is_flint(x)), plf::nan(eve::as(x)), x);
88 auto [fn, xr, dxr] = plf::rem2(x);
89 return plf::if_else(plf::is_eqz(x), plf::nan(eve::as(x)),
90 plf::rec[pedantic](sin_finalize(a0, plf::quadrant(fn), xr, dxr)));
91 }
92 else if constexpr (O::contains(eve::deg))
93 {
94 if constexpr (O::contains(eve::quarter_circle)) return plf::rec[eve::pedantic](plf::sin[eve::deg][o](a0));
95 else
96 {
97 auto a0_180 = plf::div_180(a0);
98 auto test = plf::is_nez(a0_180) && plf::is_flint(a0_180);
99 return plf::if_else(test, plf::nan(eve::as(a0)), plf::rec[eve::pedantic](plf::sin[eve::deg][o](a0)));
100 }
101 }
102 94 else return plf::rec[pedantic](plf::sin[o](a0));
103 }
104 }
105
106 namespace plf
107 {
108 constexpr auto cscd = plf::csc[eve::deg];
109 constexpr auto cscpi = plf::csc[eve::radpi];
110 }
111