-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of the pow functions family
- Loading branch information
Showing
16 changed files
with
912 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//====================================================================================================================== | ||
/* | ||
Kyosu - Complex Without Complexes | ||
Copyright : KYOSU Contributors & Maintainers | ||
SPDX-License-Identifier: BSL-1.0 | ||
*/ | ||
//====================================================================================================================== | ||
#pragma once | ||
#include <eve/module/math.hpp> | ||
|
||
namespace kyosu::_ | ||
{ | ||
template<kyosu::concepts::complex C> | ||
KYOSU_FORCEINLINE constexpr | ||
auto dispatch(eve::tag_of<kyosu::arg> const&, C const& c) noexcept | ||
{ | ||
return eve::pedantic(eve::atan2(kyosu::imag(c), kyosu::real(c)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//====================================================================================================================== | ||
/* | ||
Kyosu - Complex Without Complexes | ||
Copyright : KYOSU Contributors & Maintainers | ||
SPDX-License-Identifier: BSL-1.0 | ||
*/ | ||
//====================================================================================================================== | ||
#pragma once | ||
|
||
#include <kyosu/details/invoke.hpp> | ||
|
||
namespace kyosu::tags | ||
{ | ||
struct callable_polar : eve::elementwise | ||
{ | ||
using callable_tag_type = callable_polar; | ||
|
||
KYOSU_DEFERS_CALLABLE(polar_); | ||
|
||
template<eve::ordered_value T0, eve::ordered_value T1> | ||
static KYOSU_FORCEINLINE auto deferred_call(auto, T0 const& rho, T1 const & theta) noexcept | ||
{ | ||
auto [s, c] = eve::sincos(theta); | ||
return kyosu::to_complex(rho*c, eve::if_else(eve::is_eqz(s), eve::zero, rho*s)); | ||
} | ||
|
||
template<typename T0, typename T1> | ||
KYOSU_FORCEINLINE auto operator()(T0 const& target0, T1 const& target1) const noexcept | ||
-> decltype(eve::tag_invoke(*this, target0, target1)) | ||
{ | ||
return eve::tag_invoke(*this, target0, target1); | ||
} | ||
|
||
template<typename... T> | ||
eve::unsupported_call<callable_polar(T&&...)> operator()(T&&... x) const | ||
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; | ||
}; | ||
} | ||
|
||
namespace kyosu | ||
{ | ||
//====================================================================================================================== | ||
//! @addtogroup functions | ||
//! @{ | ||
//! @var polar | ||
//! @brief complex number from modulus and argument. | ||
//! | ||
//! **Defined in Header** | ||
//! | ||
//! @code | ||
//! #include <kyosu/functions.hpp> | ||
//! @endcode | ||
//! | ||
//! @groupheader{Callable Signatures} | ||
//! | ||
//! @code | ||
//! namespace kyosu | ||
//! { | ||
//! template<eve::ordered_value T0, eve::ordered_value T1> constexpr auto polar(T0 rho, T1 theta) noexcept; | ||
//! } | ||
//! @endcode | ||
//! | ||
//! **Parameters** | ||
//! | ||
//! * `rho` : modulus. | ||
//! * `theta` : argument. | ||
//! | ||
//! **Return value** | ||
//! | ||
//! Returns elementwise true the polarument of the complex number i.e. \f$\rho e^{i\theta}\f$. | ||
//! | ||
//! @groupheader{Example} | ||
//! | ||
//! @godbolt{doc/polar.cpp} | ||
//! @} | ||
//====================================================================================================================== | ||
inline constexpr tags::callable_polar polar = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//====================================================================================================================== | ||
/* | ||
Kyosu - Complex Without Complexes | ||
Copyright : KYOSU Contributors & Maintainers | ||
SPDX-License-Identifier: BSL-1.0 | ||
*/ | ||
//====================================================================================================================== | ||
#pragma once | ||
|
||
#include <kyosu/details/invoke.hpp> | ||
#include <kyosu/functions/to_complex.hpp> | ||
#include <eve/module/math.hpp> | ||
|
||
namespace kyosu::tags | ||
{ | ||
struct callable_log_abs : eve::elementwise | ||
{ | ||
using callable_tag_type = callable_log_abs; | ||
|
||
KYOSU_DEFERS_CALLABLE(log_abs_); | ||
|
||
template<eve::ordered_value T> | ||
static KYOSU_FORCEINLINE auto deferred_call(auto, T const& v) noexcept | ||
{ | ||
auto fn = callable_log_abs{}; | ||
return fn( kyosu::to_complex(v, T(0))); | ||
} | ||
|
||
template<typename T> | ||
KYOSU_FORCEINLINE auto operator()(T const& target) const noexcept -> decltype(eve::tag_invoke(*this, target)) | ||
{ | ||
return eve::tag_invoke(*this, target); | ||
} | ||
|
||
template<typename... T> | ||
eve::unsupported_call<callable_log_abs(T&&...)> operator()(T&&... x) const | ||
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; | ||
}; | ||
} | ||
|
||
namespace kyosu | ||
{ | ||
//====================================================================================================================== | ||
//! @addtogroup functions | ||
//! @{ | ||
//! @var log_abs | ||
//! @brief Computes the natural logarithm of the absolute value of the argument. | ||
//! | ||
//! **Defined in Header** | ||
//! | ||
//! @code | ||
//! #include <kyosu/functions.hpp> | ||
//! @endcode | ||
//! | ||
//! @groupheader{Callable Signatures} | ||
//! | ||
//! @code | ||
//! namespace kyosu | ||
//! { | ||
//! template<kyosu::concepts::cayley_dickson T> constlog_absr T log_abs(T z) noexcept; | ||
//! template<eve::ordered_value T> constlog_absr T log_abs(T z) noexcept; | ||
//! } | ||
//! @endcode | ||
//! | ||
//! **Parameters** | ||
//! | ||
//! * `z` : Value to process. | ||
//! | ||
//! **Return value** | ||
//! | ||
//! Returns the `log(abs(z))`. | ||
//! | ||
//! @groupheader{Example} | ||
//! | ||
//! @godbolt{doc/log_abs.cpp} | ||
//! @} | ||
//====================================================================================================================== | ||
inline constexpr tags::callable_log_abs log_abs = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//====================================================================================================================== | ||
/* | ||
Kyosu - Complex Without Complexes | ||
Copyright : KYOSU Contributors & Maintainers | ||
SPDX-License-Identifier: BSL-1.0 | ||
*/ | ||
//====================================================================================================================== | ||
#pragma once | ||
|
||
#include <kyosu/details/invoke.hpp> | ||
namespace kyosu::tags | ||
{ | ||
struct callable_pow : eve::elementwise | ||
{ | ||
using callable_tag_type = callable_pow; | ||
|
||
KYOSU_DEFERS_CALLABLE(pow_); | ||
|
||
static KYOSU_FORCEINLINE auto deferred_call(auto | ||
, eve::ordered_value auto const& v0 | ||
, eve::ordered_value auto const& v1) noexcept | ||
{ | ||
return eve::pow(v0, v1); | ||
} | ||
|
||
KYOSU_FORCEINLINE auto operator()(auto const& target0, auto const& target1) const noexcept | ||
-> decltype(eve::tag_invoke(*this, target0, target1)) | ||
{ | ||
return eve::tag_invoke(*this, target0, target1); | ||
} | ||
|
||
template<typename... T> | ||
eve::unsupported_call<callable_pow(T&&...)> operator()(T&&... x) const | ||
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; | ||
}; | ||
} | ||
|
||
namespace kyosu | ||
{ | ||
//====================================================================================================================== | ||
//! @addtogroup functions | ||
//! @{ | ||
//! @var pow | ||
//! @brief Computes the computing the pow operation \f$x^y\f$. | ||
//! | ||
//! **Defined in Header** | ||
//! | ||
//! @code | ||
//! #include <kyosu/functions.hpp> | ||
//! @endcode | ||
//! | ||
//! @groupheader{Callable Signatures} | ||
//! | ||
//! @code | ||
//! namespace kyosu | ||
//! { | ||
//! template<kyosu::concepts::cayley_dickson T0, kyosu::concepts::cayley_dickson T1 > constexpr auto pow(T0 z0, T1, z1) noexcept; | ||
//! template<eve::ordered_value T0, kyosu::concepts::cayley_dickson T1> > constexpr auto pow(T0 z0, T1, z1) noexcept; | ||
//! template<kyosu::concepts::cayley_dickson T0, eve::ordered_value T1 > constexpr auto pow(T0 z0, T1, z1) noexcept; | ||
//! template<eve::ordered_value T0, ordered_value T1> > constexpr auto pow(T0 z0, T1, z1) noexcept; | ||
///! } | ||
//! @endcode | ||
//! | ||
//! **Parameters** | ||
//! | ||
//! * `z0, z1` : Values to process. | ||
//! | ||
//! **Return value** | ||
//! | ||
//! the call is semantically equivalent to `eve::exp(z1*eve::log(z0))` | ||
//! | ||
//! @groupheader{Example} | ||
//! | ||
//! @godbolt{doc/pow.cpp} | ||
//! @} | ||
//====================================================================================================================== | ||
inline constexpr tags::callable_pow pow = {}; | ||
} |
Oops, something went wrong.