Skip to content

Commit

Permalink
exp_ipi pow_abs
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap committed Nov 24, 2024
1 parent 3f25749 commit 1c312d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
1 change: 1 addition & 0 deletions include/kyosu/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <kyosu/functions/rec.hpp>
#include <kyosu/functions/reldist.hpp>
#include <kyosu/functions/sign.hpp>
#include <kyosu/functions/signnz.hpp>
#include <kyosu/functions/slerp.hpp>
#include <kyosu/functions/sqr.hpp>
#include <kyosu/functions/sqr_abs.hpp>
Expand Down
46 changes: 20 additions & 26 deletions include/kyosu/functions/exp_ipi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,28 @@ namespace kyosu
{
template<concepts::cayley_dickson Z>
KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept
{ return KYOSU_CALL(z); }

{
if constexpr(concepts::complex<Z>)
{
auto [rz, iz] = muli(z);
auto [s, c] = eve::sinpicospi(iz);
auto rho = eve::exp(rz*eve::pi(eve::as(rz)));
return eve::if_else(kyosu::is_real(z) || rz == eve::minf(eve::as(rz)),
kyosu::complex(rho, eve::zero(eve::as(rho))),
kyosu::complex(rho*c, rho*s)
);
}
else
{
return exp(muli(z)*pi(as(z))); //extend can't work here
}
}
template<concepts::real V>
KYOSU_FORCEINLINE constexpr complex_t<V> operator()(V v) const noexcept
{ return KYOSU_CALL(v); }
{
auto [s, c] = eve::sinpicospi(v);
return complex(c, s);
}

KYOSU_CALLABLE_OBJECT(exp_ipi_t, exp_ipi_);
};
Expand Down Expand Up @@ -66,26 +83,3 @@ namespace kyosu
//! @}
//======================================================================================================================
}

namespace kyosu::_
{
template<typename Z, eve::callable_options O>
KYOSU_FORCEINLINE constexpr auto exp_ipi_(KYOSU_DELAY(), O const&, Z z) noexcept
{
if constexpr(kyosu::concepts::complex<Z>)
{
auto [rz, iz] = muli(z);
auto [s, c] = eve::sinpicospi(iz);
auto rho = eve::exp(rz*eve::pi(eve::as(rz)));
return eve::if_else(kyosu::is_real(z) || rz == eve::minf(eve::as(rz)),
kyosu::complex(rho, eve::zero(eve::as(rho))),
kyosu::complex(rho*c, rho*s)
);
}
else
{
const auto ipi = muli(kyosu::pi(eve::as_element<Z>()));
return kyosu::exp(ipi*z);
}
}
}
4 changes: 2 additions & 2 deletions include/kyosu/functions/pow_abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace kyosu
{ return eve::pow_abs(v0,v1); }

template<typename V0, eve::integral_value V1>
KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept -> decltype(abs(v0)+v1)
{ return eve::pow(eve::abs(v0),v1); }
KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept -> decltype(kyosu::abs(v0)+v1)
{ return eve::pow(kyosu::abs(v0),v1); }

KYOSU_CALLABLE_OBJECT(pow_abs_t, pow_abs_);
};
Expand Down

0 comments on commit 1c312d8

Please sign in to comment.