| 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/cos.hpp> | ||
| 15 | |||
| 16 | namespace plf | ||
| 17 | { | ||
| 18 | |||
| 19 | template<typename Options> | ||
| 20 | struct sec_t : plf::elementwise_callable<sec_t, | ||
| 21 | eve::sec_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(sec_t, sec_); | |
| 39 | }; | ||
| 40 | //====================================================================================================================== | ||
| 41 | //! @addtogroup math | ||
| 42 | //! @{ | ||
| 43 | //! @var sec | ||
| 44 | //! @brief return the secant 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 sec(T z) noexcept; | ||
| 58 | //! } | ||
| 59 | //! @endcode | ||
| 60 | //! | ||
| 61 | //! **Parameters** | ||
| 62 | //! | ||
| 63 | //! * `z`: Value to process. | ||
| 64 | //! | ||
| 65 | //! **Return value** | ||
| 66 | //! | ||
| 67 | //! Returns the secant of z. | ||
| 68 | //! | ||
| 69 | //! @groupheader{Example} | ||
| 70 | //! | ||
| 71 | //! @godbolt{doc/math/sec.cpp} | ||
| 72 | //====================================================================================================================== | ||
| 73 | |||
| 74 | inline constexpr auto sec = eve::functor<sec_t>; | ||
| 75 | //====================================================================================================================== | ||
| 76 | //! @} | ||
| 77 | //====================================================================================================================== | ||
| 78 | } | ||
| 79 | |||
| 80 | namespace plf::_ | ||
| 81 | { | ||
| 82 | 94 | template<typename T, eve::callable_options O> constexpr auto sec_(POLYFLOAT_DELAY(), O const& o, T a0) noexcept | |
| 83 | { | ||
| 84 | if constexpr (O::contains(eve::radpi)) | ||
| 85 | { | ||
| 86 | if constexpr (O::contains(eve::quarter_circle)) | ||
| 87 | { | ||
| 88 | auto x = abs(a0); | ||
| 89 | auto test = plf::is_not_less_equal(x, T(0.25)); | ||
| 90 | a0 = plf::if_else(test, plf::nan(eve::as(a0)), a0); | ||
| 91 | a0 *= plf::pi(eve::as<T>()); | ||
| 92 | auto x2 = plf::sqr(a0); | ||
| 93 | return plf::rec[eve::pedantic](cos_eval(x2)); | ||
| 94 | } | ||
| 95 | else | ||
| 96 | { | ||
| 97 | auto x = plf::abs(a0); | ||
| 98 | auto z = plf::cospi[o](x); | ||
| 99 | return plf::if_else(plf::is_nez(z) && plf::is_finite(a0), plf::rec[eve::pedantic](z), plf::nan(as(a0))); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | else if constexpr (O::contains(eve::deg)) | ||
| 103 | { | ||
| 104 | if constexpr (O::contains(eve::quarter_circle)) return plf::rec[pedantic](plf::cos[eve::deg][o](a0)); | ||
| 105 | else | ||
| 106 | { | ||
| 107 | auto a0_180 = plf::div_180(a0); | ||
| 108 | auto test = plf::is_not_flint(a0_180) && plf::is_flint(a0_180 + plf::mhalf(eve::as(a0_180))); | ||
| 109 | return plf::if_else(test, plf::nan(eve::as(a0)), plf::rec[eve::pedantic](plf::cos[eve::deg][o](a0))); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | 94 | else return plf::rec[eve::pedantic](plf::cos[o](a0)); | |
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | namespace plf | ||
| 117 | { | ||
| 118 | constexpr auto secd = plf::sec[eve::deg]; | ||
| 119 | constexpr auto secpi = plf::sec[eve::radpi]; | ||
| 120 | } | ||
| 121 |