| 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/atan2.hpp> | ||
| 15 | |||
| 16 | namespace plf | ||
| 17 | { | ||
| 18 | |||
| 19 | template<typename Options> | ||
| 20 | struct arg_t : plf::elementwise_callable<arg_t, | ||
| 21 | eve::arg_t, | ||
| 22 | Options, | ||
| 23 | raw_option, | ||
| 24 | pedantic_option, | ||
| 25 | eve::rad_option, | ||
| 26 | eve::radpi_option, | ||
| 27 | eve::deg_option> | ||
| 28 | { | ||
| 29 | 854 | template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept | |
| 30 | { | ||
| 31 | 854 | return POLYFLOAT_CALL(z); | |
| 32 | } | ||
| 33 | |||
| 34 | 844 | POLYFLOAT_CALLABLE_OBJECT(arg_t, arg_); | |
| 35 | }; | ||
| 36 | //====================================================================================================================== | ||
| 37 | //! @addtogroup math | ||
| 38 | //! @{ | ||
| 39 | //! @var arg | ||
| 40 | //! @brief return the the phase angle (in radians). | ||
| 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 | //! // Regular overload | ||
| 54 | //! constexpr auto arg(floating_value auto x) noexcept; // 1 | ||
| 55 | //! | ||
| 56 | //! // Lanes masking | ||
| 57 | //! constexpr auto arg[conditional_expr auto c](value auto x) noexcept; // 2 | ||
| 58 | //! constexpr auto arg[logical_value auto m](value auto x) noexcept; // 2 | ||
| 59 | //! | ||
| 60 | //! // Semantic option | ||
| 61 | //! constexpr auto arg[pedantic](floating_value auto x) noexcept; // 3 | ||
| 62 | //! constexpr auto arg[rad](floating_value auto x) noexcept; // 1 | ||
| 63 | //! constexpr auto arg[deg](floating_value auto x) noexcept; // 4 | ||
| 64 | //! constexpr auto arg[radpi](floating_value auto x) noexcept; // 5 | ||
| 65 | //! } | ||
| 66 | //! @endcode | ||
| 67 | //! | ||
| 68 | //! **Parameters** | ||
| 69 | //! | ||
| 70 | //! * `z`: Value to process. | ||
| 71 | //! | ||
| 72 | //! **Return value** | ||
| 73 | //! | ||
| 74 | //! 1. Returns [elementwise](@ref glossary_elementwise) the phase angle (in radians) of the | ||
| 75 | //! input (0 or\f$\pi\f$) depending of the bit of sign of the input | ||
| 76 | //! 2. [The operation is performed conditionally](@ref conditional). | ||
| 77 | //! 3. If the entry is `NaN` the result is `NaN`. | ||
| 78 | //! 4. Result in degrees | ||
| 79 | //! 5. Result in \f$\pi\f$ multiples | ||
| 80 | //! | ||
| 81 | //! @note phase can be used as an alias | ||
| 82 | //! | ||
| 83 | //! @groupheader{Example} | ||
| 84 | //! | ||
| 85 | //! @groupheader{External references} | ||
| 86 | //! * [C++ standard reference](https://en.cppreference.com/w/cpp/numeric/complex/arg) | ||
| 87 | //! | ||
| 88 | //! @godbolt_todo{doc/core/arg.cpp} | ||
| 89 | //====================================================================================================================== | ||
| 90 | |||
| 91 | inline constexpr auto arg = eve::functor<arg_t>; | ||
| 92 | inline constexpr auto phase = eve::functor<arg_t>; | ||
| 93 | |||
| 94 | //====================================================================================================================== | ||
| 95 | //! @} | ||
| 96 | //====================================================================================================================== | ||
| 97 | } | ||
| 98 | |||
| 99 | namespace plf::_ | ||
| 100 | { | ||
| 101 | 844 | template<typename T, eve::callable_options O> constexpr auto arg_(POLYFLOAT_DELAY(), O const&, T a) noexcept | |
| 102 | { | ||
| 103 | 422 | auto valneg = [](auto x) { | |
| 104 | if constexpr (O::contains(eve::deg)) return T(180); | ||
| 105 | else if constexpr (O::contains(eve::radpi)) return plf::one(eve::as(x)); | ||
| 106 |
8/8✓ Branch 2 taken 104 times.
✓ Branch 6 taken 104 times.
✓ Branch 10 taken 104 times.
✓ Branch 14 taken 106 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
|
422 | else return plf::pi(eve::as(x)); |
| 107 | }; | ||
| 108 | 844 | auto z = plf::if_else(is_negative(a), valneg(a), eve::zero); | |
| 109 | if constexpr (eve::platform::supports_nans && O::contains(pedantic)) | ||
| 110 | return plf::if_else(plf::is_nan(a), plf::nan(eve::as(z)), z); | ||
| 111 | 844 | else return z; | |
| 112 | } | ||
| 113 | |||
| 114 | constexpr auto argd = plf::arg[eve::deg]; | ||
| 115 | constexpr auto argpi = plf::arg[eve::radpi]; | ||
| 116 | constexpr auto phased = plf::arg[eve::deg]; | ||
| 117 | constexpr auto phasepi = plf::arg[eve::radpi]; | ||
| 118 | } | ||
| 119 |