From 7c1dbe5918769c65a00c8386c3b4db9c79351919 Mon Sep 17 00:00:00 2001 From: jtlap Date: Sun, 24 Nov 2024 19:54:11 +0100 Subject: [PATCH] Simplify callable --- include/kyosu/core.hpp | 1 + include/kyosu/functions/abs.hpp | 29 +++---- include/kyosu/functions/acos.hpp | 2 +- include/kyosu/functions/acosh.hpp | 2 +- include/kyosu/functions/acospi.hpp | 13 +-- include/kyosu/functions/acot.hpp | 11 +-- include/kyosu/functions/acoth.hpp | 12 +-- include/kyosu/functions/acotpi.hpp | 13 +-- include/kyosu/functions/acsc.hpp | 13 +-- include/kyosu/functions/acsch.hpp | 13 +-- include/kyosu/functions/acscpi.hpp | 13 +-- include/kyosu/functions/airy_ai.hpp | 23 ++---- include/kyosu/functions/airy_bi.hpp | 23 ++---- include/kyosu/functions/arg.hpp | 20 ++--- include/kyosu/functions/asec.hpp | 13 +-- include/kyosu/functions/asech.hpp | 12 +-- include/kyosu/functions/asecpi.hpp | 13 +-- include/kyosu/functions/asin.hpp | 2 +- include/kyosu/functions/asinh.hpp | 28 +++---- include/kyosu/functions/asinpi.hpp | 13 +-- include/kyosu/functions/atan.hpp | 39 ++++----- include/kyosu/functions/atanh.hpp | 2 +- include/kyosu/functions/atanpi.hpp | 13 +-- include/kyosu/functions/beta.hpp | 17 ++-- include/kyosu/functions/ceil.hpp | 11 +-- include/kyosu/functions/conj.hpp | 19 +---- include/kyosu/functions/cos.hpp | 25 ++---- include/kyosu/functions/cosh.hpp | 51 +++++------- include/kyosu/functions/cospi.hpp | 53 ++++++------ include/kyosu/functions/cot.hpp | 27 +++---- include/kyosu/functions/coth.hpp | 28 +++---- include/kyosu/functions/cotpi.hpp | 33 +++----- include/kyosu/functions/csc.hpp | 12 +-- include/kyosu/functions/csch.hpp | 13 +-- include/kyosu/functions/cscpi.hpp | 12 +-- include/kyosu/functions/cyl_bessel_h1_0.hpp | 2 +- include/kyosu/functions/cyl_bessel_h1_1.hpp | 2 +- include/kyosu/functions/cyl_bessel_h2_0.hpp | 2 +- include/kyosu/functions/cyl_bessel_h2_1.hpp | 2 +- include/kyosu/functions/dec.hpp | 17 ++-- include/kyosu/functions/deta.hpp | 2 +- include/kyosu/functions/digamma.hpp | 2 +- include/kyosu/functions/dot.hpp | 11 +-- include/kyosu/functions/erfcx.hpp | 39 ++++----- include/kyosu/functions/erfi.hpp | 54 +++++-------- include/kyosu/functions/eta.hpp | 13 +-- include/kyosu/functions/exp.hpp | 39 ++++----- include/kyosu/functions/exp10.hpp | 11 +-- include/kyosu/functions/exp2.hpp | 11 +-- include/kyosu/functions/exp_i.hpp | 13 +-- include/kyosu/functions/exp_ipi.hpp | 46 +++++------ include/kyosu/functions/expm1.hpp | 47 +++++------ include/kyosu/functions/expmx2.hpp | 11 +-- include/kyosu/functions/expx2.hpp | 11 +-- include/kyosu/functions/faddeeva.hpp | 2 +- include/kyosu/functions/fam.hpp | 11 +-- include/kyosu/functions/floor.hpp | 11 +-- include/kyosu/functions/fma.hpp | 11 +-- include/kyosu/functions/fms.hpp | 11 +-- include/kyosu/functions/fnma.hpp | 11 +-- include/kyosu/functions/fnms.hpp | 11 +-- include/kyosu/functions/frac.hpp | 11 +-- include/kyosu/functions/fsm.hpp | 11 +-- include/kyosu/functions/hypot.hpp | 16 +--- include/kyosu/functions/inc.hpp | 17 ++-- include/kyosu/functions/is_denormal.hpp | 15 +--- include/kyosu/functions/is_equal.hpp | 24 ++---- include/kyosu/functions/is_eqz.hpp | 17 ++-- include/kyosu/functions/is_finite.hpp | 14 +--- include/kyosu/functions/is_imag.hpp | 14 +--- include/kyosu/functions/is_infinite.hpp | 18 ++--- include/kyosu/functions/is_nan.hpp | 16 ++-- include/kyosu/functions/is_nez.hpp | 19 ++--- include/kyosu/functions/is_not_denormal.hpp | 14 +--- include/kyosu/functions/is_not_equal.hpp | 22 ++--- include/kyosu/functions/is_not_finite.hpp | 14 +--- include/kyosu/functions/is_not_infinite.hpp | 18 ++--- include/kyosu/functions/is_not_nan.hpp | 14 +--- include/kyosu/functions/is_not_real.hpp | 38 ++++----- include/kyosu/functions/is_pure.hpp | 11 +-- include/kyosu/functions/is_real.hpp | 30 +++---- include/kyosu/functions/is_unitary.hpp | 34 ++++---- include/kyosu/functions/lambda.hpp | 37 ++++----- include/kyosu/functions/lbeta.hpp | 13 +-- include/kyosu/functions/ldiv.hpp | 11 +-- include/kyosu/functions/lerp.hpp | 17 ++-- include/kyosu/functions/log.hpp | 51 +++++------- include/kyosu/functions/log10.hpp | 51 +++++------- include/kyosu/functions/log1p.hpp | 39 ++++----- include/kyosu/functions/log2.hpp | 53 ++++++------ include/kyosu/functions/log_abs.hpp | 11 +-- include/kyosu/functions/log_abs_gamma.hpp | 13 +-- include/kyosu/functions/log_gamma.hpp | 2 +- include/kyosu/functions/lpnorm.hpp | 16 +--- include/kyosu/functions/manhattan.hpp | 16 +--- include/kyosu/functions/maxabs.hpp | 13 +-- include/kyosu/functions/maxmag.hpp | 45 +++++------ include/kyosu/functions/minabs.hpp | 13 +-- include/kyosu/functions/minmag.hpp | 45 +++++------ include/kyosu/functions/minus.hpp | 11 +-- include/kyosu/functions/muli.hpp | 27 +++---- include/kyosu/functions/mulmi.hpp | 27 +++---- include/kyosu/functions/nearest.hpp | 11 +-- include/kyosu/functions/negmaxabs.hpp | 4 +- include/kyosu/functions/negminabs.hpp | 4 +- include/kyosu/functions/oneminus.hpp | 11 +-- include/kyosu/functions/pow.hpp | 2 +- include/kyosu/functions/pow_abs.hpp | 34 +++----- include/kyosu/functions/pure.hpp | 23 ++---- include/kyosu/functions/radinpi.hpp | 13 +-- include/kyosu/functions/rec.hpp | 15 +--- include/kyosu/functions/reldist.hpp | 8 -- include/kyosu/functions/sec.hpp | 13 +-- include/kyosu/functions/sech.hpp | 13 +-- include/kyosu/functions/secpi.hpp | 13 +-- include/kyosu/functions/sign.hpp | 15 +--- include/kyosu/functions/signnz.hpp | 13 +-- include/kyosu/functions/sin.hpp | 26 ++---- include/kyosu/functions/sinc.hpp | 31 +++---- include/kyosu/functions/sincos.hpp | 33 ++++---- include/kyosu/functions/sinh.hpp | 61 +++++++------- include/kyosu/functions/sinhc.hpp | 31 +++---- include/kyosu/functions/sinhcosh.hpp | 84 +++++++++---------- include/kyosu/functions/sinpi.hpp | 59 ++++++-------- include/kyosu/functions/sinpicospi.hpp | 89 ++++++++++----------- include/kyosu/functions/slerp.hpp | 35 ++++---- include/kyosu/functions/sph_bessel_h1_0.hpp | 2 +- include/kyosu/functions/sph_bessel_h1_1.hpp | 2 +- include/kyosu/functions/sph_bessel_h2_0.hpp | 2 +- include/kyosu/functions/sph_bessel_h2_1.hpp | 2 +- include/kyosu/functions/sph_bessel_i1_0.hpp | 2 +- include/kyosu/functions/sph_bessel_i1_1.hpp | 2 +- include/kyosu/functions/sph_bessel_i2_0.hpp | 2 +- include/kyosu/functions/sph_bessel_i2_1.hpp | 2 +- include/kyosu/functions/sph_bessel_k0.hpp | 2 +- include/kyosu/functions/sph_bessel_k1.hpp | 2 +- include/kyosu/functions/sqr.hpp | 41 ++++------ include/kyosu/functions/sqr_abs.hpp | 27 +++---- include/kyosu/functions/sqrt.hpp | 2 +- include/kyosu/functions/tan.hpp | 26 ++---- include/kyosu/functions/tanh.hpp | 41 ++++------ include/kyosu/functions/tanpi.hpp | 49 +++++------- include/kyosu/functions/to_complex.hpp | 24 +----- include/kyosu/functions/to_polar.hpp | 2 +- include/kyosu/functions/trunc.hpp | 11 +-- include/kyosu/functions/zeta.hpp | 16 +++- test/unit/function/acot.cpp | 2 +- test/unit/function/atan.cpp | 2 +- test/unit/function/atanh.cpp | 2 +- test/unit/quaternion/slerp.cpp | 41 ---------- 150 files changed, 953 insertions(+), 1919 deletions(-) delete mode 100644 test/unit/quaternion/slerp.cpp diff --git a/include/kyosu/core.hpp b/include/kyosu/core.hpp index 37cb2669..3320c567 100644 --- a/include/kyosu/core.hpp +++ b/include/kyosu/core.hpp @@ -86,6 +86,7 @@ #include #include #include +#include #include #include #include diff --git a/include/kyosu/functions/abs.hpp b/include/kyosu/functions/abs.hpp index 6bdf03c5..d0d0dc5c 100644 --- a/include/kyosu/functions/abs.hpp +++ b/include/kyosu/functions/abs.hpp @@ -15,10 +15,19 @@ namespace kyosu struct abs_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr as_real_type_t operator()(Z z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr as_real_type_t operator()(Z v) const noexcept + { + if constexpr(Options::contains(eve::raw)) + return eve::hypot(v); + else + return eve::hypot[eve::pedantic](v); + } template - KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return KYOSU_CALL(v); } + KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept + { + return eve::abs(v); + } KYOSU_CALLABLE_OBJECT(abs_t, abs_); }; @@ -68,19 +77,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto abs_(KYOSU_DELAY(), O const&, Z const& v) noexcept - { - if constexpr(concepts::cayley_dickson){ - if constexpr(O::contains(eve::raw)) - return eve::hypot(v); - else - return eve::hypot[eve::pedantic](v); - } - else - return eve::abs(v); - } -} diff --git a/include/kyosu/functions/acos.hpp b/include/kyosu/functions/acos.hpp index 46180f78..e8d9a689 100644 --- a/include/kyosu/functions/acos.hpp +++ b/include/kyosu/functions/acos.hpp @@ -25,7 +25,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(acos_t, acos_); }; diff --git a/include/kyosu/functions/acosh.hpp b/include/kyosu/functions/acosh.hpp index 356d40d2..ba0ade64 100644 --- a/include/kyosu/functions/acosh.hpp +++ b/include/kyosu/functions/acosh.hpp @@ -24,7 +24,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(acosh_t, acosh_); }; diff --git a/include/kyosu/functions/acospi.hpp b/include/kyosu/functions/acospi.hpp index 51c888ac..95ecc12a 100644 --- a/include/kyosu/functions/acospi.hpp +++ b/include/kyosu/functions/acospi.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return radinpi(kyosu::acos(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(acospi_t, acospi_); }; @@ -69,12 +69,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto acospi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return radinpi(kyosu::acos(z)); - } -} diff --git a/include/kyosu/functions/acot.hpp b/include/kyosu/functions/acot.hpp index c4a1efec..e4d7ff0b 100644 --- a/include/kyosu/functions/acot.hpp +++ b/include/kyosu/functions/acot.hpp @@ -19,7 +19,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::atan(kyosu::rec(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -78,12 +78,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto acot_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::atan(kyosu::rec(z)); - } -} diff --git a/include/kyosu/functions/acoth.hpp b/include/kyosu/functions/acoth.hpp index 277fc523..9ca4b881 100644 --- a/include/kyosu/functions/acoth.hpp +++ b/include/kyosu/functions/acoth.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::atanh(kyosu::rec(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(acoth_t, acoth_); }; @@ -79,11 +79,3 @@ namespace kyosu //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto acoth_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::atanh(kyosu::rec(z)); - } -} diff --git a/include/kyosu/functions/acotpi.hpp b/include/kyosu/functions/acotpi.hpp index f47b2212..47df91f6 100644 --- a/include/kyosu/functions/acotpi.hpp +++ b/include/kyosu/functions/acotpi.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return radinpi(kyosu::acot(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(acotpi_t, acotpi_); }; @@ -69,12 +69,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto acotpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return radinpi(kyosu::acot(z)); - } -} diff --git a/include/kyosu/functions/acsc.hpp b/include/kyosu/functions/acsc.hpp index cb36c7d8..681a93a2 100644 --- a/include/kyosu/functions/acsc.hpp +++ b/include/kyosu/functions/acsc.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::asin(kyosu::rec(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(acsc_t, acsc_); }; @@ -73,12 +73,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto acsc_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::asin(kyosu::rec(z)); - } -} diff --git a/include/kyosu/functions/acsch.hpp b/include/kyosu/functions/acsch.hpp index 932b0507..028f87e4 100644 --- a/include/kyosu/functions/acsch.hpp +++ b/include/kyosu/functions/acsch.hpp @@ -18,11 +18,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return asinh(rec(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(acsch_t, acsch_); }; @@ -69,12 +69,3 @@ namespace kyosu //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto acsch_(KYOSU_DELAY(), O const&, Z z) noexcept - { - Z r = kyosu::rec(z); - return kyosu::asinh(r); - } -} diff --git a/include/kyosu/functions/acscpi.hpp b/include/kyosu/functions/acscpi.hpp index e316f38b..cbe09d97 100644 --- a/include/kyosu/functions/acscpi.hpp +++ b/include/kyosu/functions/acscpi.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return radinpi(kyosu::acsc(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(acscpi_t, acscpi_); }; @@ -69,12 +69,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto acscpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return radinpi(kyosu::acsc(z)); - } -} diff --git a/include/kyosu/functions/airy_ai.hpp b/include/kyosu/functions/airy_ai.hpp index bfd39d02..1f8c206f 100644 --- a/include/kyosu/functions/airy_ai.hpp +++ b/include/kyosu/functions/airy_ai.hpp @@ -16,7 +16,12 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(kyosu::concepts::complex ) + return _::ai(z); + else + return kyosu::_::cayley_extend(*this, z); + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,19 +69,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto airy_ai_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(kyosu::concepts::complex ) - { - return ai(z); - } - else - { - return cayley_extend(airy_ai, z); - } - } -} diff --git a/include/kyosu/functions/airy_bi.hpp b/include/kyosu/functions/airy_bi.hpp index 1f3d3342..3b15ac30 100644 --- a/include/kyosu/functions/airy_bi.hpp +++ b/include/kyosu/functions/airy_bi.hpp @@ -16,7 +16,12 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(kyosu::concepts::complex ) + return _::bi(z); + else + return kyosu::_::cayley_extend(*this, z); + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -68,19 +73,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto airy_bi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - return bi(z); - } - else - { - return cayley_extend(airy_bi, z); - } - } -} diff --git a/include/kyosu/functions/arg.hpp b/include/kyosu/functions/arg.hpp index b128ef2b..418be7ea 100644 --- a/include/kyosu/functions/arg.hpp +++ b/include/kyosu/functions/arg.hpp @@ -15,10 +15,16 @@ namespace kyosu struct arg_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr as_real_type_t operator()(Z z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr as_real_type_t operator()(Z v) const noexcept + { + if constexpr(concepts::complex) return eve::atan2[ eve::pedantic](imag(v), real(v)); + else return eve::atan2[ eve::pedantic](eve::sign(imag(v))*abs(pure(v)), real(v)); + } template - KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return KYOSU_CALL(v); } + KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { + return eve::if_else(eve::is_positive(v), eve::zero, eve::pi(eve::as(v))); + } KYOSU_CALLABLE_OBJECT(arg_t, arg_); }; @@ -66,13 +72,3 @@ namespace kyosu //! @} //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto arg_(KYOSU_DELAY(), O const&, Z const& v) noexcept - { - if constexpr(concepts::complex) return eve::atan2[ eve::pedantic]( imag(v), real(v)); - else if constexpr(concepts::cayley_dickson) return eve::atan2[ eve::pedantic]( eve::sign(imag(v))*abs(pure(v)), real(v)); - else return eve::if_else( eve::is_positive(v), eve::zero, eve::pi(eve::as(v))); - } -} diff --git a/include/kyosu/functions/asec.hpp b/include/kyosu/functions/asec.hpp index ec7d75e0..25f8e940 100644 --- a/include/kyosu/functions/asec.hpp +++ b/include/kyosu/functions/asec.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::acos(kyosu::rec(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(asec_t, asec_); }; @@ -72,12 +72,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto asec_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::acos(kyosu::rec(z)); - } -} diff --git a/include/kyosu/functions/asech.hpp b/include/kyosu/functions/asech.hpp index 9aadf5c7..4a5a3062 100644 --- a/include/kyosu/functions/asech.hpp +++ b/include/kyosu/functions/asech.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::acosh(kyosu::rec(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(asech_t, asech_); }; @@ -73,11 +73,3 @@ namespace kyosu //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto asech_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::acosh(kyosu::rec(z)); - } -} diff --git a/include/kyosu/functions/asecpi.hpp b/include/kyosu/functions/asecpi.hpp index a603ca2b..dbe7d348 100644 --- a/include/kyosu/functions/asecpi.hpp +++ b/include/kyosu/functions/asecpi.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return radinpi(kyosu::asec(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(asecpi_t, asecpi_); }; @@ -69,12 +69,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto asecpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return radinpi(kyosu::asec(z)); - } -} diff --git a/include/kyosu/functions/asin.hpp b/include/kyosu/functions/asin.hpp index 056d889c..8399b292 100644 --- a/include/kyosu/functions/asin.hpp +++ b/include/kyosu/functions/asin.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(asin_t, asin_); }; diff --git a/include/kyosu/functions/asinh.hpp b/include/kyosu/functions/asinh.hpp index 64b751df..bcb591e8 100644 --- a/include/kyosu/functions/asinh.hpp +++ b/include/kyosu/functions/asinh.hpp @@ -8,6 +8,7 @@ #pragma once #include "eve/traits/as_logical.hpp" #include +#include #include #include #include @@ -19,7 +20,16 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + return mulmi( kyosu::asin(muli(z))); + } + else + { + return kyosu::_::cayley_extend((*this), z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -91,19 +101,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto asinh_(KYOSU_DELAY(), O const&, Z a0) noexcept - { - if constexpr(concepts::complex ) - { - return mulmi( kyosu::asin(muli(a0))); - } - else - { - return cayley_extend(asinh, a0); - } - } -} diff --git a/include/kyosu/functions/asinpi.hpp b/include/kyosu/functions/asinpi.hpp index c1bb5503..e52d2a9a 100644 --- a/include/kyosu/functions/asinpi.hpp +++ b/include/kyosu/functions/asinpi.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return radinpi(kyosu::asin(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(asinpi_t, asinpi_); }; @@ -69,12 +69,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto asinpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return radinpi(kyosu::asin(z)); - } -} diff --git a/include/kyosu/functions/atan.hpp b/include/kyosu/functions/atan.hpp index 5f8f9cfc..d754b2c1 100644 --- a/include/kyosu/functions/atan.hpp +++ b/include/kyosu/functions/atan.hpp @@ -18,14 +18,26 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + // C99 definition here; atan(z) = -i atanh(i*z): + auto [r, i] = z; + auto [r1, i1] = kyosu::atanh(complex(-i, r)); + return complex(i1, -r1); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template - KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept + { return eve::atan(v); } KYOSU_CALLABLE_OBJECT(atan_t, atan_); -}; + }; //====================================================================================================================== //! @addtogroup functions @@ -81,22 +93,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto atan_(KYOSU_DELAY(), O const&, Z a0) noexcept - { - if constexpr(concepts::complex ) - { - // C99 definition here; atan(a0) = -i atanh(ia0): - auto [r, i] = a0; - auto [r1, i1] = kyosu::atanh(complex(-i, r)); - return complex(i1, -r1); - } - else - { - return cayley_extend(atan, a0); - } - } -} diff --git a/include/kyosu/functions/atanh.hpp b/include/kyosu/functions/atanh.hpp index 674fbb88..f5b19952 100644 --- a/include/kyosu/functions/atanh.hpp +++ b/include/kyosu/functions/atanh.hpp @@ -22,7 +22,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(atanh_t, atanh_); }; diff --git a/include/kyosu/functions/atanpi.hpp b/include/kyosu/functions/atanpi.hpp index 6a0d0312..c32f9996 100644 --- a/include/kyosu/functions/atanpi.hpp +++ b/include/kyosu/functions/atanpi.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return radinpi(kyosu::atan(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v));; } + { return (*this)(complex(v));; } KYOSU_CALLABLE_OBJECT(atanpi_t, atanpi_); }; @@ -69,12 +69,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto atanpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return radinpi(kyosu::atan(z)); - } -} diff --git a/include/kyosu/functions/beta.hpp b/include/kyosu/functions/beta.hpp index 9f9369cb..1a052f34 100644 --- a/include/kyosu/functions/beta.hpp +++ b/include/kyosu/functions/beta.hpp @@ -19,11 +19,14 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr as_cayley_dickson_t operator()(Z0 const& z0, Z1 const & z1) const noexcept - { return KYOSU_CALL(z0,z1); } + { + auto y = z0 + z1; + return tgamma(z0)*tgamma(z1)/tgamma(y); + } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept -> decltype(beta(complex(v0),v1)) - { return beta(complex(v0),complex(v1)); } + { return (*this)(complex(v0),complex(v1)); } KYOSU_CALLABLE_OBJECT(beta_t, beta_); }; @@ -68,13 +71,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto beta_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1) noexcept - { - auto y = z0 + z1; - return tgamma(z0)*tgamma(z1)/tgamma(y); - } -} diff --git a/include/kyosu/functions/ceil.hpp b/include/kyosu/functions/ceil.hpp index 7565fc9d..6134b1ef 100644 --- a/include/kyosu/functions/ceil.hpp +++ b/include/kyosu/functions/ceil.hpp @@ -16,7 +16,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return Z{kumi::map([](auto const& e) { return eve::ceil(e); }, z)}; } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,12 +64,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto ceil_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return Z{kumi::map([](auto const& e) { return eve::ceil(e); }, c)}; - } -} diff --git a/include/kyosu/functions/conj.hpp b/include/kyosu/functions/conj.hpp index 5edd96b3..043cc20e 100644 --- a/include/kyosu/functions/conj.hpp +++ b/include/kyosu/functions/conj.hpp @@ -15,10 +15,12 @@ namespace kyosu struct conj_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z z) const noexcept + { return Z{kumi::map_index([](I, auto m) { if constexpr(I::value>0) return -m; else return m;}, z)};} + template - KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return KYOSU_CALL(v); } + KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return v; } KYOSU_CALLABLE_OBJECT(conj_t, conj_); }; @@ -66,16 +68,3 @@ inline constexpr auto conj = eve::functor; //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto conj_(KYOSU_DELAY(), O const&, Z const& v) noexcept - { - if constexpr(concepts::cayley_dickson) - { - return Z{kumi::map_index([](I, auto m) { if constexpr(I::value>0) return -m; else return m;}, v)}; - } - else return v; - } -} diff --git a/include/kyosu/functions/cos.hpp b/include/kyosu/functions/cos.hpp index 63305919..6d7a28f2 100644 --- a/include/kyosu/functions/cos.hpp +++ b/include/kyosu/functions/cos.hpp @@ -9,7 +9,7 @@ #include "eve/traits/as_logical.hpp" #include #include - +#include namespace kyosu { template @@ -17,7 +17,12 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + return cosh(muli(z)); + else + return kyosu::_::cayley_extend(*this, z); + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -71,19 +76,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto cos_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - return cosh(Z(-kyosu::imag(z), kyosu::real(z))); - } - else - { - return cayley_extend(cos, z); - } - } -} diff --git a/include/kyosu/functions/cosh.hpp b/include/kyosu/functions/cosh.hpp index 65a9455e..f8115c61 100644 --- a/include/kyosu/functions/cosh.hpp +++ b/include/kyosu/functions/cosh.hpp @@ -19,7 +19,28 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto [rz, iz] = z; + auto [s, c] = eve::sincos(iz); + auto [sh, ch] = eve::sinhcosh(rz); + auto r = c*ch; + auto i = s*sh; + i = eve::if_else(kyosu::is_eqz(kyosu::ipart(z)) || kyosu::is_real(z), eve::zero, i); + auto res = Z(r, i); + if (eve::any(kyosu::is_not_finite(z))) + { + res = eve::if_else(eve::is_infinite(rz) && eve::is_not_finite(iz), Z(eve::inf(eve::as(rz)), eve::nan(eve::as(rz))), res); + res = eve::if_else(eve::is_nan(rz) && eve::is_infinite(iz), Z(eve::nan(eve::as(rz)), eve::nan(eve::as(rz))), res); + } + return res; + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -86,31 +107,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto cosh_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto [rz, iz] = z; - auto [s, c] = eve::sincos(iz); - auto [sh, ch] = eve::sinhcosh(rz); - auto r = c*ch; - auto i = s*sh; - i = eve::if_else(kyosu::is_eqz(kyosu::ipart(z)) || kyosu::is_real(z), eve::zero, i); - auto res = Z(r, i); - if (eve::any(kyosu::is_not_finite(z))) - { - res = eve::if_else(eve::is_infinite(rz) && eve::is_not_finite(iz), Z(eve::inf(eve::as(rz)), eve::nan(eve::as(rz))), res); - res = eve::if_else(eve::is_nan(rz) && eve::is_infinite(iz), Z(eve::nan(eve::as(rz)), eve::nan(eve::as(rz))), res); - } - return res; - } - else - { - return cayley_extend(cosh, z); - } - } -} diff --git a/include/kyosu/functions/cospi.hpp b/include/kyosu/functions/cospi.hpp index 8e98fd68..f93fa2db 100644 --- a/include/kyosu/functions/cospi.hpp +++ b/include/kyosu/functions/cospi.hpp @@ -17,7 +17,29 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto [rz, iz] = z; + iz *= eve::pi(eve::as(iz)); + auto [s, c] = eve::sinpicospi(rz); + auto [sh, ch] = eve::sinhcosh(iz); + auto r = c*ch; + auto i = eve::if_else(is_imag(z) || kyosu::is_real(z),eve::zero, -s*sh); + if (eve::any(kyosu::is_not_finite(z))) + { + r = eve::if_else(eve::is_infinite(iz) && eve::is_not_finite(rz), eve::inf(eve::as(r)), r); + i = eve::if_else(eve::is_infinite(iz) && eve::is_not_finite(rz), eve::nan(eve::as(r)), i); + r = eve::if_else(eve::is_nan(iz) && eve::is_infinite(rz), eve::allbits, r); + i = eve::if_else(eve::is_nan(iz) && eve::is_infinite(rz), eve::allbits, i); + } + return kyosu::complex(r, i); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,32 +87,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto cospi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto [rz, iz] = z; - iz *= eve::pi(eve::as(iz)); - auto [s, c] = eve::sinpicospi(rz); - auto [sh, ch] = eve::sinhcosh(iz); - auto r = c*ch; - auto i = eve::if_else(is_imag(z) || kyosu::is_real(z),eve::zero, -s*sh); - if (eve::any(kyosu::is_not_finite(z))) - { - r = eve::if_else(eve::is_infinite(iz) && eve::is_not_finite(rz), eve::inf(eve::as(r)), r); - i = eve::if_else(eve::is_infinite(iz) && eve::is_not_finite(rz), eve::nan(eve::as(r)), i); - r = eve::if_else(eve::is_nan(iz) && eve::is_infinite(rz), eve::allbits, r); - i = eve::if_else(eve::is_nan(iz) && eve::is_infinite(rz), eve::allbits, i); - } - return kyosu::complex(r, i); - } - else - { - return cayley_extend(cospi, z); - } - } -} diff --git a/include/kyosu/functions/cot.hpp b/include/kyosu/functions/cot.hpp index b510b944..ffc6ed78 100644 --- a/include/kyosu/functions/cot.hpp +++ b/include/kyosu/functions/cot.hpp @@ -18,7 +18,16 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + return kyosu::rec(kyosu::tan(z)); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -66,19 +75,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto cot_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - return kyosu::rec(kyosu::tan(z)); - } - else - { - return cayley_extend(cot, z); - } - } -} diff --git a/include/kyosu/functions/coth.hpp b/include/kyosu/functions/coth.hpp index 2fb1c024..fc40b41a 100644 --- a/include/kyosu/functions/coth.hpp +++ b/include/kyosu/functions/coth.hpp @@ -17,8 +17,17 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } - + { + if constexpr(concepts::complex ) + { + return kyosu::rec(kyosu::tanh(z)); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } + template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return eve::coth(v); } @@ -66,18 +75,3 @@ namespace kyosu //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto coth_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - return kyosu::rec(kyosu::tanh(z)); - } - else - { - return cayley_extend(coth, z); - } - } -} diff --git a/include/kyosu/functions/cotpi.hpp b/include/kyosu/functions/cotpi.hpp index 7f7540f9..f90e0ed2 100644 --- a/include/kyosu/functions/cotpi.hpp +++ b/include/kyosu/functions/cotpi.hpp @@ -18,7 +18,19 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto r = kyosu::tanpi(z); + r = kyosu::if_else(kyosu::is_infinite(r), eve::zero, kyosu::rec(r)); + r = kyosu::if_else(kyosu::is_real(z) && eve::is_flint(kyosu::real(z)*2) && eve::is_not_flint(kyosu::real(z)), eve::zero, r); + return kyosu::if_else(kyosu::is_real(z), kyosu::complex(kyosu::real(r)), r); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -66,22 +78,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto cotpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto r = kyosu::tanpi(z); - r = kyosu::if_else(kyosu::is_infinite(r), eve::zero, kyosu::rec(r)); - r = kyosu::if_else(kyosu::is_real(z) && eve::is_flint(kyosu::real(z)*2) && eve::is_not_flint(kyosu::real(z)), eve::zero, r); - return kyosu::if_else(kyosu::is_real(z), kyosu::complex(kyosu::real(r)), r); - } - else - { - return cayley_extend(cotpi, z); - } - } -} diff --git a/include/kyosu/functions/csc.hpp b/include/kyosu/functions/csc.hpp index c17bc6c7..828b46c2 100644 --- a/include/kyosu/functions/csc.hpp +++ b/include/kyosu/functions/csc.hpp @@ -9,6 +9,7 @@ #include "eve/traits/as_logical.hpp" #include #include +#include namespace kyosu { @@ -17,7 +18,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::rec(kyosu::sin(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto csc_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::rec(kyosu::sin(z)); - } -} diff --git a/include/kyosu/functions/csch.hpp b/include/kyosu/functions/csch.hpp index f36b33ba..688e95a0 100644 --- a/include/kyosu/functions/csch.hpp +++ b/include/kyosu/functions/csch.hpp @@ -8,6 +8,8 @@ #pragma once #include "eve/traits/as_logical.hpp" #include +#include +#include namespace kyosu { @@ -16,7 +18,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::rec(kyosu::sinh(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto csch_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::rec(kyosu::sinh(z)); - } -} diff --git a/include/kyosu/functions/cscpi.hpp b/include/kyosu/functions/cscpi.hpp index 09f8b4f9..e13eb069 100644 --- a/include/kyosu/functions/cscpi.hpp +++ b/include/kyosu/functions/cscpi.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace kyosu @@ -19,7 +20,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::rec(kyosu::sinpi(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -67,12 +68,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto cscpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::rec(kyosu::sinpi(z)); - } -} diff --git a/include/kyosu/functions/cyl_bessel_h1_0.hpp b/include/kyosu/functions/cyl_bessel_h1_0.hpp index 05fc823d..95c73e91 100644 --- a/include/kyosu/functions/cyl_bessel_h1_0.hpp +++ b/include/kyosu/functions/cyl_bessel_h1_0.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(cyl_bessel_h1_0_t, cyl_bessel_h1_0_); }; diff --git a/include/kyosu/functions/cyl_bessel_h1_1.hpp b/include/kyosu/functions/cyl_bessel_h1_1.hpp index 47dd10b5..e0aae41d 100644 --- a/include/kyosu/functions/cyl_bessel_h1_1.hpp +++ b/include/kyosu/functions/cyl_bessel_h1_1.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(cyl_bessel_h1_1_t, cyl_bessel_h1_1_); }; diff --git a/include/kyosu/functions/cyl_bessel_h2_0.hpp b/include/kyosu/functions/cyl_bessel_h2_0.hpp index 3f6e58d8..d9d815a9 100644 --- a/include/kyosu/functions/cyl_bessel_h2_0.hpp +++ b/include/kyosu/functions/cyl_bessel_h2_0.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(cyl_bessel_h2_0_t, cyl_bessel_h2_0_); diff --git a/include/kyosu/functions/cyl_bessel_h2_1.hpp b/include/kyosu/functions/cyl_bessel_h2_1.hpp index 0e0cec64..98cf2d39 100644 --- a/include/kyosu/functions/cyl_bessel_h2_1.hpp +++ b/include/kyosu/functions/cyl_bessel_h2_1.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(cyl_bessel_h2_1_t, cyl_bessel_h2_1_); }; diff --git a/include/kyosu/functions/dec.hpp b/include/kyosu/functions/dec.hpp index 5672301b..6864c85b 100644 --- a/include/kyosu/functions/dec.hpp +++ b/include/kyosu/functions/dec.hpp @@ -15,8 +15,11 @@ namespace kyosu struct dec_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z c) const noexcept + { + real(c) = eve::dec(real(c)); + return c; + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,13 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto dec_(KYOSU_DELAY(), O const&, Z c) noexcept - { - real(c) = eve::dec(real(c)); - return c; - } -} diff --git a/include/kyosu/functions/deta.hpp b/include/kyosu/functions/deta.hpp index cc033303..992a46f6 100644 --- a/include/kyosu/functions/deta.hpp +++ b/include/kyosu/functions/deta.hpp @@ -26,7 +26,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(K k, V v) const noexcept - { return KYOSU_CALL(k, complex(v)); } + { return (*this)(k, complex(v)); } KYOSU_CALLABLE_OBJECT(deta_t, deta_); }; diff --git a/include/kyosu/functions/digamma.hpp b/include/kyosu/functions/digamma.hpp index cc5719ba..ce1a2abd 100644 --- a/include/kyosu/functions/digamma.hpp +++ b/include/kyosu/functions/digamma.hpp @@ -24,7 +24,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(digamma_t, digamma_); }; diff --git a/include/kyosu/functions/dot.hpp b/include/kyosu/functions/dot.hpp index f7043be1..519adb46 100644 --- a/include/kyosu/functions/dot.hpp +++ b/include/kyosu/functions/dot.hpp @@ -18,7 +18,7 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1) const noexcept -> as_cayley_dickson_t - { return KYOSU_CALL(z0,z1); } + { return z0*conj(z1);; } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept -> decltype(v0*v1) @@ -68,12 +68,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto dot_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1) noexcept - { - return z0*conj(z1); - } -} diff --git a/include/kyosu/functions/erfcx.hpp b/include/kyosu/functions/erfcx.hpp index ee32ed2f..616584e5 100644 --- a/include/kyosu/functions/erfcx.hpp +++ b/include/kyosu/functions/erfcx.hpp @@ -18,7 +18,22 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto realz = is_real(z); + if (eve::all(realz)) + return complex(eve::erfcx(real(z))); + else if (eve::none(realz)) + return faddeeva(muli(z)); + else + return if_else(realz, complex(eve::erfcx(real(z))), faddeeva(muli(z))); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -69,25 +84,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto erfcx_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto realz = is_real(z); - if (eve::all(realz)) - return complex(eve::erfcx(real(z))); - else if (eve::none(realz)) - return faddeeva(complex(-imag(z), real(z))); - else - return if_else(realz, complex(eve::erfcx(real(z))), faddeeva(complex(-imag(z), real(z)))); - } - else - { - return cayley_extend(erfcx, z); - } - } -} diff --git a/include/kyosu/functions/erfi.hpp b/include/kyosu/functions/erfi.hpp index 5c0e5f5a..5d92378c 100644 --- a/include/kyosu/functions/erfi.hpp +++ b/include/kyosu/functions/erfi.hpp @@ -22,11 +22,28 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + if (eve::all(is_real(z))) + return complex((*this)(real(z))); + else + return mulmi(erf(muli(z))); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template - KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(v); } + KYOSU_FORCEINLINE constexpr complex_t operator()(V z) const noexcept + { + auto over = eve::sqr(z) > 720; + auto r = eve::inf(eve::as(z))*eve::sign(z); + r = eve::if_else(over, r, -imag(kyosu::erf(complex(eve::zero(eve::as(z)), -z)))); + return complex(r); + } KYOSU_CALLABLE_OBJECT(erfi_t, erfi_); }; @@ -70,34 +87,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto erfi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::real ) - { - auto over = eve::sqr(z) > 720; - auto r = eve::inf(eve::as(z))*eve::sign(z); - r = eve::if_else(over, r, -get<1>(kyosu::erf(complex(eve::zero(eve::as(z)), -z)))); - return complex(r); - } - else if constexpr(concepts::complex ) - { - auto realz = is_real(z); - if (eve::all(realz)) - { - return kyosu::erfi(real(z)); - } - else - { - return mulmi(erf(muli(z))); - } - } - else - { - return cayley_extend(erfi, z); - } - } -} diff --git a/include/kyosu/functions/eta.hpp b/include/kyosu/functions/eta.hpp index 53005795..dec8730e 100644 --- a/include/kyosu/functions/eta.hpp +++ b/include/kyosu/functions/eta.hpp @@ -18,11 +18,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return deta(1u, z); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(eta_t, eta_); }; @@ -67,12 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto eta_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return deta(1u, z); - } -} diff --git a/include/kyosu/functions/exp.hpp b/include/kyosu/functions/exp.hpp index 71d7414f..085755e7 100644 --- a/include/kyosu/functions/exp.hpp +++ b/include/kyosu/functions/exp.hpp @@ -20,7 +20,22 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto [rz, iz] = z; + auto [s, c] = eve::sincos(iz); + auto rho = eve::if_else(is_nan(rz), eve::allbits, eve::exp(rz)); + auto res = eve::if_else(is_real(z) || rz == eve::minf(eve::as(rz)), + Z(rho, eve::zero(eve::as(rho))), + Z(rho*c, rho*s)); + return if_else(rz == eve::inf(eve::as(rz)) && eve::is_not_finite(iz), Z{rz, eve::nan(eve::as(iz))}, res); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -88,25 +103,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto exp_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto [rz, iz] = z; - auto [s, c] = eve::sincos(iz); - auto rho = eve::if_else(is_nan(rz), eve::allbits, eve::exp(rz)); - auto res = eve::if_else(is_real(z) || rz == eve::minf(eve::as(rz)), - Z(rho, eve::zero(eve::as(rho))), - Z(rho*c, rho*s)); - return if_else(rz == eve::inf(eve::as(rz)) && eve::is_not_finite(iz), Z{rz, eve::nan(eve::as(iz))}, res); - } - else - { - return cayley_extend(exp, z); - } - } -} diff --git a/include/kyosu/functions/exp10.hpp b/include/kyosu/functions/exp10.hpp index 1b2482aa..a47364aa 100644 --- a/include/kyosu/functions/exp10.hpp +++ b/include/kyosu/functions/exp10.hpp @@ -17,7 +17,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::exp(z*kyosu::log_10(eve::as_element())); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto exp10_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::exp(z*kyosu::log_10(eve::as_element())); - } -} diff --git a/include/kyosu/functions/exp2.hpp b/include/kyosu/functions/exp2.hpp index 467970ec..c92c4bb2 100644 --- a/include/kyosu/functions/exp2.hpp +++ b/include/kyosu/functions/exp2.hpp @@ -17,7 +17,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::exp(z*kyosu::log_2(eve::as_element())); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto exp2_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::exp(z*kyosu::log_2(eve::as_element())); - } -} diff --git a/include/kyosu/functions/exp_i.hpp b/include/kyosu/functions/exp_i.hpp index 96524af6..aca2c45d 100644 --- a/include/kyosu/functions/exp_i.hpp +++ b/include/kyosu/functions/exp_i.hpp @@ -18,11 +18,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::exp(muli(z)); } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(v); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(exp_i_t, exp_i_); }; @@ -66,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto exp_i_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::exp(muli(z)); - } -} diff --git a/include/kyosu/functions/exp_ipi.hpp b/include/kyosu/functions/exp_ipi.hpp index 61c82bf2..157b9f53 100644 --- a/include/kyosu/functions/exp_ipi.hpp +++ b/include/kyosu/functions/exp_ipi.hpp @@ -18,11 +18,28 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } - + { + if constexpr(concepts::complex) + { + 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 KYOSU_FORCEINLINE constexpr complex_t 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_); }; @@ -66,26 +83,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto exp_ipi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(kyosu::concepts::complex) - { - 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())); - return kyosu::exp(ipi*z); - } - } -} diff --git a/include/kyosu/functions/expm1.hpp b/include/kyosu/functions/expm1.hpp index a6446b54..b4622287 100644 --- a/include/kyosu/functions/expm1.hpp +++ b/include/kyosu/functions/expm1.hpp @@ -16,7 +16,25 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(kyosu::concepts::complex) + { + auto [rz, iz] = z; + auto [siz, ciz] = eve::sincos(iz); + auto cosm1 = [siz, ciz](auto b) { + return eve::if_else(abs(ciz) < eve::pio_4(eve::as(b)) + , eve::dec(ciz), -eve::sqr(siz)/(eve::inc(ciz))); + }; + auto r = eve::fma(eve::expm1(rz), ciz, cosm1(iz)); + auto i = eve::exp(rz)*siz; + r = eve::if_else(rz == eve::inf(eve::as(rz)) && eve::is_not_finite(iz), rz, r); + return complex(r, eve::if_else(kyosu::is_real(z), eve::zero, i)); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,30 +83,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto expm1_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(kyosu::concepts::complex) - { - auto [rz, iz] = z; - auto sc = eve::sincos(iz); - auto siz = get<0>(sc); - auto ciz = get<1>(sc); - auto cosm1 = [siz, ciz](auto b) { - return eve::if_else(abs(ciz) < eve::pio_4(eve::as(b)) - , eve::dec(ciz), -eve::sqr(siz)/(eve::inc(ciz))); - }; - auto r = eve::fma(expm1(rz), ciz, cosm1(iz)); - auto i = eve::exp(rz)*siz; - r = eve::if_else(rz == eve::inf(eve::as(rz)) && eve::is_not_finite(iz), rz, r); - return complex(r, eve::if_else(kyosu::is_real(z), eve::zero, i)); - } - else - { - return cayley_extend(expm1, z); - } - } -} diff --git a/include/kyosu/functions/expmx2.hpp b/include/kyosu/functions/expmx2.hpp index 6fabb479..882ce5b5 100644 --- a/include/kyosu/functions/expmx2.hpp +++ b/include/kyosu/functions/expmx2.hpp @@ -18,7 +18,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::exp(-sqr(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -66,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto expmx2_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::exp(-sqr(z)); - } -} diff --git a/include/kyosu/functions/expx2.hpp b/include/kyosu/functions/expx2.hpp index 5e0a405a..6dc41b02 100644 --- a/include/kyosu/functions/expx2.hpp +++ b/include/kyosu/functions/expx2.hpp @@ -18,7 +18,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return exp(sqr(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -66,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto expx2_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return exp(sqr(z)); - } -} diff --git a/include/kyosu/functions/faddeeva.hpp b/include/kyosu/functions/faddeeva.hpp index a523cf78..41c24dea 100644 --- a/include/kyosu/functions/faddeeva.hpp +++ b/include/kyosu/functions/faddeeva.hpp @@ -21,7 +21,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(faddeeva_t, faddeeva_); }; diff --git a/include/kyosu/functions/fam.hpp b/include/kyosu/functions/fam.hpp index 98d193d4..3598961c 100644 --- a/include/kyosu/functions/fam.hpp +++ b/include/kyosu/functions/fam.hpp @@ -18,7 +18,7 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1, Z2 const & z2) const noexcept -> decltype(z0+z1+z2) - { return KYOSU_CALL(z0,z1,z2); } + { return z0+z1*z2; } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept -> decltype(v0+v1+v2) @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto fam_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1, Z2 z2) noexcept - { - return z0+z1*z2; - } -} diff --git a/include/kyosu/functions/floor.hpp b/include/kyosu/functions/floor.hpp index 9007f47d..a44f6654 100644 --- a/include/kyosu/functions/floor.hpp +++ b/include/kyosu/functions/floor.hpp @@ -16,7 +16,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return Z{kumi::map([](auto const& e) { return eve::floor(e); }, z)}; } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,12 +64,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto floor_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return Z{kumi::map([](auto const& e) { return eve::floor(e); }, c)}; - } -} diff --git a/include/kyosu/functions/fma.hpp b/include/kyosu/functions/fma.hpp index 2b975b6d..4d5d99a5 100644 --- a/include/kyosu/functions/fma.hpp +++ b/include/kyosu/functions/fma.hpp @@ -18,7 +18,7 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1, Z2 const & z2) const noexcept -> decltype(z0+z1+z2) - { return KYOSU_CALL(z0,z1,z2); } + { return z0*z1+z2; } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept -> decltype(v0+v1+v2) @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto fma_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1, Z2 z2) noexcept - { - return z0*z1+z2; - } -} diff --git a/include/kyosu/functions/fms.hpp b/include/kyosu/functions/fms.hpp index 0e35e691..3d076fac 100644 --- a/include/kyosu/functions/fms.hpp +++ b/include/kyosu/functions/fms.hpp @@ -18,7 +18,7 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1, Z2 const & z2) const noexcept -> decltype(z0+z1+z2) - { return KYOSU_CALL(z0,z1,z2); } + { return z0*z1-z2; } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept -> decltype(v0+v1+v2) @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto fms_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1, Z2 z2) noexcept - { - return z0*z1-z2; - } -} diff --git a/include/kyosu/functions/fnma.hpp b/include/kyosu/functions/fnma.hpp index 2c93026c..51ee6926 100644 --- a/include/kyosu/functions/fnma.hpp +++ b/include/kyosu/functions/fnma.hpp @@ -18,7 +18,7 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1, Z2 const & z2) const noexcept -> decltype(z0+z1+z2) - { return KYOSU_CALL(z0,z1,z2); } + { return z2-z0*z1; } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept -> decltype(v0+v1+v2) @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto fnma_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1, Z2 z2) noexcept - { - return z2-z0*z1; - } -} diff --git a/include/kyosu/functions/fnms.hpp b/include/kyosu/functions/fnms.hpp index d9b810b8..ad257566 100644 --- a/include/kyosu/functions/fnms.hpp +++ b/include/kyosu/functions/fnms.hpp @@ -18,7 +18,7 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1, Z2 const & z2) const noexcept -> decltype(z0+z1+z2) - { return KYOSU_CALL(z0,z1,z2); } + { return -z0*z1-z2;; } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept -> decltype(v0+v1+v2) @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto fnms_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1, Z2 z2) noexcept - { - return -z0*z1-z2; - } -} diff --git a/include/kyosu/functions/frac.hpp b/include/kyosu/functions/frac.hpp index bb495b44..8e1021e1 100644 --- a/include/kyosu/functions/frac.hpp +++ b/include/kyosu/functions/frac.hpp @@ -16,7 +16,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return Z{kumi::map([](auto const& e) { return eve::frac(e); }, z)}; } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto frac_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return Z{kumi::map([](auto const& e) { return eve::frac(e); }, c)}; - } -} diff --git a/include/kyosu/functions/fsm.hpp b/include/kyosu/functions/fsm.hpp index 720ce7d6..8b42a009 100644 --- a/include/kyosu/functions/fsm.hpp +++ b/include/kyosu/functions/fsm.hpp @@ -18,7 +18,7 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1, Z2 const & z2) const noexcept -> decltype(z0+z1+z2) - { return KYOSU_CALL(z0,z1,z2); } + { return z1*z2-z0; } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept -> decltype(v0+v1+v2) @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto fsm_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1, Z2 z2) noexcept - { - return z1*z2-z0; - } -} diff --git a/include/kyosu/functions/hypot.hpp b/include/kyosu/functions/hypot.hpp index 8aec4b0e..ad1e7db7 100644 --- a/include/kyosu/functions/hypot.hpp +++ b/include/kyosu/functions/hypot.hpp @@ -18,11 +18,11 @@ namespace kyosu template requires(concepts::cayley_dickson || (concepts::cayley_dickson || ...)) KYOSU_FORCEINLINE constexpr auto operator()(Z0 z0, Zs ... zs) const noexcept -> decltype(eve::hypot(real(z0), real(zs)...)) - { return KYOSU_CALL(z0,zs...); } + { return eve::hypot[this->options()](kumi::flatten(kumi::make_tuple(z0, zs...))); } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, Vs... vs) const noexcept -> decltype( eve::manhattan(v0, vs...)) - { return eve::hypot(v0,vs...); } + { return eve::hypot[this->options()](v0,vs...); } KYOSU_CALLABLE_OBJECT(hypot_t, hypot_); }; @@ -67,15 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto hypot_(KYOSU_DELAY(), O const& o, Z0 z0, Zs... zs) noexcept - { - if constexpr(concepts::cayley_dickson || (concepts::cayley_dickson || ...) ) - return eve::hypot[o](kumi::flatten(kumi::make_tuple(z0, zs...))); - else - return eve::hypot[o](z0, zs...); - } -} diff --git a/include/kyosu/functions/inc.hpp b/include/kyosu/functions/inc.hpp index 7f26c676..5a5e978c 100644 --- a/include/kyosu/functions/inc.hpp +++ b/include/kyosu/functions/inc.hpp @@ -15,8 +15,11 @@ namespace kyosu struct inc_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z c) const noexcept + { + real(c) = eve::inc(real(c)); + return c; + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,13 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr Z inc_(KYOSU_DELAY(), O const&, Z c) noexcept - { - real(c) = eve::inc(real(c)); - return c; - } -} diff --git a/include/kyosu/functions/is_denormal.hpp b/include/kyosu/functions/is_denormal.hpp index 702efddd..904fb24a 100644 --- a/include/kyosu/functions/is_denormal.hpp +++ b/include/kyosu/functions/is_denormal.hpp @@ -15,8 +15,10 @@ namespace kyosu struct is_denormal_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } - + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& c) const noexcept + { + return kumi::any_of(c, [](auto const& e) { return eve::is_denormal(e); }); + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_denormal(v); } @@ -62,12 +64,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_denormal_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kumi::any_of(c, [](auto const& e) { return eve::is_denormal(e); }); - } -} diff --git a/include/kyosu/functions/is_equal.hpp b/include/kyosu/functions/is_equal.hpp index 76e530bc..35775bb6 100644 --- a/include/kyosu/functions/is_equal.hpp +++ b/include/kyosu/functions/is_equal.hpp @@ -19,14 +19,19 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1) const noexcept -> eve::as_logical_t - { return KYOSU_CALL(z0,z1); } + { + if constexpr(Options::contains(eve::numeric)) + return (z0 == z1) || (is_nan(z0) && is_nan(z1)); + else + return z0 == z1; + } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept -> eve::as_logical_t - { return eve::is_equal[Options()](v0, v1); } + { return eve::is_equal[this->options()](v0, v1); } KYOSU_CALLABLE_OBJECT(is_equal_t, is_equal_); -}; + }; //====================================================================================================================== //! @addtogroup functions @@ -71,16 +76,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_equal_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1) noexcept - -> eve::as_logical_t - { - if constexpr(O::contains(eve::numeric)) - return (z0 == z1) || (is_nan(z0) && is_nan(z1)); - else - return z0 == z1; - } -} diff --git a/include/kyosu/functions/is_eqz.hpp b/include/kyosu/functions/is_eqz.hpp index b76d1902..b6c87daf 100644 --- a/include/kyosu/functions/is_eqz.hpp +++ b/include/kyosu/functions/is_eqz.hpp @@ -16,14 +16,17 @@ namespace kyosu struct is_eqz_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return z == eve::zero(as(z)); + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_eqz(v); } - + KYOSU_CALLABLE_OBJECT(is_eqz_t, is_eqz_); }; - + //====================================================================================================================== //! @addtogroup functions //! @{ @@ -64,11 +67,3 @@ namespace kyosu //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_eqz_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return z == eve::zero(as(z)); - } -} diff --git a/include/kyosu/functions/is_finite.hpp b/include/kyosu/functions/is_finite.hpp index 2a1c1927..5a726e04 100644 --- a/include/kyosu/functions/is_finite.hpp +++ b/include/kyosu/functions/is_finite.hpp @@ -15,7 +15,10 @@ namespace kyosu struct is_finite_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return kumi::all_of(z, [](auto const& e) { return eve::is_finite(e); }); + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_finite(v); } @@ -62,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_finite_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kumi::all_of(c, [](auto const& e) { return eve::is_finite(e); }); - } -} diff --git a/include/kyosu/functions/is_imag.hpp b/include/kyosu/functions/is_imag.hpp index ac539797..79dce06d 100644 --- a/include/kyosu/functions/is_imag.hpp +++ b/include/kyosu/functions/is_imag.hpp @@ -15,7 +15,10 @@ namespace kyosu struct is_imag_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return eve::is_eqz(real(z)); + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_eqz(v); } @@ -62,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_imag_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return eve::is_eqz(real(c)); - } -} diff --git a/include/kyosu/functions/is_infinite.hpp b/include/kyosu/functions/is_infinite.hpp index a3aea897..0fa20b3f 100644 --- a/include/kyosu/functions/is_infinite.hpp +++ b/include/kyosu/functions/is_infinite.hpp @@ -15,11 +15,14 @@ namespace kyosu struct is_infinite_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } - + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return kumi::any_of(z, [](auto e) { return eve::is_infinite(e); }); + } + template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_infinite(v); } - + KYOSU_CALLABLE_OBJECT(is_infinite_t, is_infinite_); }; @@ -62,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_infinite_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kumi::any_of(z, [](auto e) { return eve::is_infinite(e); }); - } -} diff --git a/include/kyosu/functions/is_nan.hpp b/include/kyosu/functions/is_nan.hpp index f8f37339..86d1a7df 100644 --- a/include/kyosu/functions/is_nan.hpp +++ b/include/kyosu/functions/is_nan.hpp @@ -15,8 +15,11 @@ namespace kyosu struct is_nan_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } - + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return kumi::any_of(z, [](auto const& e) { return eve::is_nan(e); }); + } + template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_nan(v); } @@ -61,12 +64,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_nan_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kumi::any_of(c, [](auto const& e) { return eve::is_nan(e); }); - } -} diff --git a/include/kyosu/functions/is_nez.hpp b/include/kyosu/functions/is_nez.hpp index e38d3788..f7a95f14 100644 --- a/include/kyosu/functions/is_nez.hpp +++ b/include/kyosu/functions/is_nez.hpp @@ -15,14 +15,17 @@ namespace kyosu struct is_nez_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } - + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return kumi::any_of(z, [](auto const& e) { return eve::is_nez(e); }); + } + template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_nez(v); } - + KYOSU_CALLABLE_OBJECT(is_nez_t, is_nez_); }; - + //====================================================================================================================== //! @addtogroup functions //! @{ @@ -62,11 +65,3 @@ namespace kyosu //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_nez_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kumi::any_of(c, [](auto const& e) { return eve::is_nez(e); }); - } -} diff --git a/include/kyosu/functions/is_not_denormal.hpp b/include/kyosu/functions/is_not_denormal.hpp index f4037713..f835c1b8 100644 --- a/include/kyosu/functions/is_not_denormal.hpp +++ b/include/kyosu/functions/is_not_denormal.hpp @@ -15,7 +15,10 @@ namespace kyosu struct is_not_denormal_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return kumi::all_of(z, [](auto const& e) { return eve::is_not_denormal(e); }); + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_not_denormal(v); } @@ -62,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_not_denormal_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kumi::all_of(c, [](auto const& e) { return eve::is_not_denormal(e); }); - } -} diff --git a/include/kyosu/functions/is_not_equal.hpp b/include/kyosu/functions/is_not_equal.hpp index f5b8c8e5..accc82bb 100644 --- a/include/kyosu/functions/is_not_equal.hpp +++ b/include/kyosu/functions/is_not_equal.hpp @@ -20,11 +20,16 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1) const noexcept -> eve::as_logical_t - { return KYOSU_CALL(z0,z1); } + { + if constexpr(Options::contains(eve::numeric)) + return (z0 != z1) || (is_not_nan(z0) && is_not_nan(z1)); + else + return z0 != z1; + } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept -> eve::as_logical_t - { return KYOSU_CALL(v0,v1); } + { return eve::is_not_equal[this->options()](v0, v1); } KYOSU_CALLABLE_OBJECT(is_not_equal_t, is_not_equal_); }; @@ -72,16 +77,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_not_equal_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1) noexcept - -> eve::as_logical_t - { - if constexpr(O::contains(eve::numeric)) - return (z0 != z1) || (is_not_nan(z0) && is_not_nan(z1)); - else - return z0 != z1; - } -} diff --git a/include/kyosu/functions/is_not_finite.hpp b/include/kyosu/functions/is_not_finite.hpp index 9b5a0bda..365a266e 100644 --- a/include/kyosu/functions/is_not_finite.hpp +++ b/include/kyosu/functions/is_not_finite.hpp @@ -15,7 +15,10 @@ namespace kyosu struct is_not_finite_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return kumi::any_of(z, [](auto const& e) { return eve::is_not_finite(e); }); + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_not_finite(v); } @@ -62,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_not_finite_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kumi::any_of(c, [](auto const& e) { return eve::is_not_finite(e); }); - } -} diff --git a/include/kyosu/functions/is_not_infinite.hpp b/include/kyosu/functions/is_not_infinite.hpp index 0d2ace39..47c8c986 100644 --- a/include/kyosu/functions/is_not_infinite.hpp +++ b/include/kyosu/functions/is_not_infinite.hpp @@ -15,11 +15,14 @@ namespace kyosu struct is_not_infinite_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } - + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return kumi::all_of(z, [](auto const& e) { return eve::is_not_infinite(e); }); + } + template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_not_infinite(v); } - + KYOSU_CALLABLE_OBJECT(is_not_infinite_t, is_not_infinite_); }; @@ -62,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_not_infinite_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kumi::all_of(c, [](auto const& e) { return eve::is_not_infinite(e); }); - } -} diff --git a/include/kyosu/functions/is_not_nan.hpp b/include/kyosu/functions/is_not_nan.hpp index 09d68be7..4dd6dc2e 100644 --- a/include/kyosu/functions/is_not_nan.hpp +++ b/include/kyosu/functions/is_not_nan.hpp @@ -15,7 +15,10 @@ namespace kyosu struct is_not_nan_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept + { + return kumi::all_of(z, [](auto const& e) { return eve::is_not_nan(e); }); + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_not_nan(v); } @@ -61,12 +64,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_not_nan_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kumi::all_of(c, [](auto const& e) { return eve::is_not_nan(e); }); - } -} diff --git a/include/kyosu/functions/is_not_real.hpp b/include/kyosu/functions/is_not_real.hpp index ecf51b34..29445dc8 100644 --- a/include/kyosu/functions/is_not_real.hpp +++ b/include/kyosu/functions/is_not_real.hpp @@ -15,15 +15,26 @@ namespace kyosu struct is_not_real_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } - + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z c) const noexcept + { + if constexpr(kyosu::concepts::complex) + { + return eve::is_nez(ipart(c)); + } + else + { + get<0>(c) = eve::zero(eve::as(get<0>(c))); + return kumi::any_of(c, [](auto const& e) { return eve::is_nez(e); }); + } + } + template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::false_(eve::as(v)); } - + KYOSU_CALLABLE_OBJECT(is_not_real_t, is_not_real_); }; - - + + //====================================================================================================================== //! @addtogroup functions //! @{ @@ -64,19 +75,4 @@ namespace kyosu //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_not_real_(KYOSU_DELAY(), O const&, Z c) noexcept - { - if constexpr(kyosu::concepts::complex) - { - return eve::is_nez(ipart(c)); - } - else - { - get<0>(c) = eve::zero(eve::as(get<0>(c))); - return kumi::any_of(c, [](auto const& e) { return eve::is_nez(e); }); - } - } -} + diff --git a/include/kyosu/functions/is_pure.hpp b/include/kyosu/functions/is_pure.hpp index 5f06cf4c..28c31f66 100644 --- a/include/kyosu/functions/is_pure.hpp +++ b/include/kyosu/functions/is_pure.hpp @@ -15,7 +15,7 @@ namespace kyosu struct is_pure_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return eve::is_eqz(real(z)); } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::is_eqz(v); } @@ -62,12 +62,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_pure_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return is_eqz(real(c)); - } -} diff --git a/include/kyosu/functions/is_real.hpp b/include/kyosu/functions/is_real.hpp index 78b493ea..f70bdb3c 100644 --- a/include/kyosu/functions/is_real.hpp +++ b/include/kyosu/functions/is_real.hpp @@ -15,7 +15,18 @@ namespace kyosu struct is_real_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z c) const noexcept + { + if constexpr(kyosu::concepts::complex) + { + return eve::is_eqz(ipart(c)); + } + else + { + get<0>(c) = eve::zero(eve::as(get<0>(c))); + return kumi::all_of(c, [](auto const& e) { return eve::is_eqz(e); }); + } + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::true_(eve::as(v)); } @@ -63,20 +74,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_real_(KYOSU_DELAY(), O const&, Z c) noexcept - { - if constexpr(kyosu::concepts::complex) - { - return eve::is_eqz(ipart(c)); - } - else - { - get<0>(c) = eve::zero(eve::as(get<0>(c))); - return kumi::all_of(c, [](auto const& e) { return eve::is_eqz(e); }); - } - } -} diff --git a/include/kyosu/functions/is_unitary.hpp b/include/kyosu/functions/is_unitary.hpp index 032af4e5..2d5e9055 100644 --- a/include/kyosu/functions/is_unitary.hpp +++ b/include/kyosu/functions/is_unitary.hpp @@ -15,7 +15,20 @@ namespace kyosu struct is_unitary_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(Z const& c) const noexcept + { + using ar_t = decltype(kyosu::sqr_abs(c)); + if constexpr(Options::contains(eve::pedantic)) + { + return kyosu::sqr_abs(c) == eve::one(eve::as()); + } + else + { + // almost is used to encompass the fact that normalization of cayley_dickson can suffer + // rounding errors. Use raw if you don't need this behavior. + return eve::is_equal[eve::almost](kyosu::sqr_abs(c), eve::one(eve::as())); + } + } template KYOSU_FORCEINLINE constexpr eve::as_logical_t operator()(V v) const noexcept { return eve::abs(v) == eve::one(eve::as(v)); } @@ -75,22 +88,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto is_unitary_(KYOSU_DELAY(), O const&, Z c) noexcept - { - using ar_t = decltype(kyosu::sqr_abs(c)); - if constexpr(O::contains(eve::pedantic)) - { - return kyosu::sqr_abs(c) == eve::one(eve::as()); - } - else - { - // almost is used to encompass the fact that normalization of cayley_dickson can suffer - // rounding errors. Whhen available use raw if you don't accept this behavior. - return eve::is_equal[eve::almost](kyosu::sqr_abs(c), eve::one(eve::as())); - } - } -} diff --git a/include/kyosu/functions/lambda.hpp b/include/kyosu/functions/lambda.hpp index da7a2906..4996a084 100644 --- a/include/kyosu/functions/lambda.hpp +++ b/include/kyosu/functions/lambda.hpp @@ -19,11 +19,24 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto zz = exp2(z); + auto k = (z-1)/(z-2); + auto r = if_else(z == complex(eve::one(eve::as(real(z)))), complex(eve::inf(eve::as(real(z)))), k*deta(1u, zz)); + imag(r) = eve::if_else(is_real(z), eve::zero, imag(r)); + return r; + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(lambda_t, lambda_); }; @@ -71,23 +84,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto lambda_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto zz=exp2(z); - auto k = (z-1)/(z-2); - auto r = if_else(z == complex(eve::one(eve::as(real(z)))), complex(eve::inf(eve::as(real(z)))), k*deta(1u, zz)); - imag(r) = eve::if_else(is_real(z), eve::zero, imag(r)); - return r; - } - else - { - return cayley_extend(cosh, z); - } - } -} diff --git a/include/kyosu/functions/lbeta.hpp b/include/kyosu/functions/lbeta.hpp index afaeadc9..47ed3cbc 100644 --- a/include/kyosu/functions/lbeta.hpp +++ b/include/kyosu/functions/lbeta.hpp @@ -20,11 +20,11 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr as_cayley_dickson_t operator()(Z0 const& z0, Z1 const & z1) const noexcept - { return KYOSU_CALL(z0,z1); } + { return kyosu::log(kyosu::beta(z0, z1)); } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept -> decltype(complex(v0)+v1) - { return KYOSU_CALL(complex(v0),v1); } + { return (*this)(complex(v0),v1); } KYOSU_CALLABLE_OBJECT(lbeta_t, lbeta_); }; @@ -67,12 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto lbeta_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1) noexcept - { - return kyosu::log(kyosu::beta(z0, z1)); - } -} diff --git a/include/kyosu/functions/ldiv.hpp b/include/kyosu/functions/ldiv.hpp index ed48a1e7..dcd6e076 100644 --- a/include/kyosu/functions/ldiv.hpp +++ b/include/kyosu/functions/ldiv.hpp @@ -18,7 +18,7 @@ namespace kyosu template requires(concepts::cayley_dickson || concepts::cayley_dickson) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1) const noexcept -> decltype(z0+z1) - { return KYOSU_CALL(z0,z1); } + { return kyosu::rec(z0)*z1; } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept -> decltype(v0+v1) @@ -66,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto ldiv_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1) noexcept - { - return kyosu::rec(z0)*z1; - } -} diff --git a/include/kyosu/functions/lerp.hpp b/include/kyosu/functions/lerp.hpp index 5e0934e9..7a4e288a 100644 --- a/include/kyosu/functions/lerp.hpp +++ b/include/kyosu/functions/lerp.hpp @@ -17,8 +17,11 @@ namespace kyosu { template requires((concepts::cayley_dickson || concepts::cayley_dickson)&& concepts::real) - KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1, Z2 const & z2) const noexcept -> decltype(z0+z1+z2) - { return KYOSU_CALL(z0,z1,z2); } + KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& c0, Z1 const & c1, Z2 const & t) const noexcept -> decltype(c0+c1+t) + { + using r_t = as_cayley_dickson_t; + return r_t{kumi::map([&t](auto const& e, auto const & f) { return eve::lerp(e, f, t); }, r_t(c0), r_t(c1))}; + } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept -> decltype(v0+v1+v2) @@ -69,13 +72,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto lerp_(KYOSU_DELAY(), O const&, C0 c0, C1 c1, T t) noexcept - { - using r_t = as_cayley_dickson_t; - return r_t{kumi::map([&t](auto const& e, auto const & f) { return eve::lerp(e, f, t); }, r_t(c0), r_t(c1))}; - } -} diff --git a/include/kyosu/functions/log.hpp b/include/kyosu/functions/log.hpp index 19022e94..d4ea2691 100644 --- a/include/kyosu/functions/log.hpp +++ b/include/kyosu/functions/log.hpp @@ -17,11 +17,31 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(kyosu::concepts::complex) + { + auto arg = [](auto zz){ return eve::atan2[eve::pedantic](kyosu::imag(zz), kyosu::real(zz));}; + auto [rz, iz] = z; + auto infty = eve::inf(eve::as(rz)); + auto argz = arg(z); + auto absz = eve::if_else(eve::is_nan(rz) && eve::is_infinite(iz), infty, kyosu::abs(z)); + auto la = eve::log(absz); + auto r = kyosu::if_else(kyosu::is_real(z) && eve::is_positive(rz), complex(la), complex(la, argz)); + if(eve::any(kyosu::is_not_finite(z))) + { + r = kyosu::if_else(eve::is_infinite(rz) && eve::is_nan(iz), complex(infty, iz), r); + } + return r; + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(log_t, log_); }; @@ -88,30 +108,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto log_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(kyosu::concepts::complex) - { - auto arg = [](auto zz){ return eve::atan2[eve::pedantic](kyosu::imag(zz), kyosu::real(zz));}; - auto [rz, iz] = z; - auto infty = eve::inf(eve::as(rz)); - auto argz = arg(z); - auto absz = eve::if_else(eve::is_nan(rz) && eve::is_infinite(iz), infty, kyosu::abs(z)); - auto la = eve::log(absz); - auto r = kyosu::if_else(kyosu::is_real(z) && eve::is_positive(rz), complex(la), complex(la, argz)); - if(eve::any(kyosu::is_not_finite(z))) - { - r = kyosu::if_else(eve::is_infinite(rz) && eve::is_nan(iz), complex(infty, iz), r); - } - return r; - } - else - { - return cayley_extend(log, z); - } - } -} diff --git a/include/kyosu/functions/log10.hpp b/include/kyosu/functions/log10.hpp index 6d619ad8..5f05edfc 100644 --- a/include/kyosu/functions/log10.hpp +++ b/include/kyosu/functions/log10.hpp @@ -16,11 +16,31 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(kyosu::concepts::complex) + { + auto [rz, iz] = z; + auto infty = eve::inf(eve::as(rz)); + auto arg = [](auto z){ return eve::atan2[eve::pedantic](kyosu::imag(z), kyosu::real(z));}; + auto argz = arg(z)*eve::invlog_10(eve::as(rz)); + auto absz = eve::if_else(eve::is_nan(rz) && eve::is_infinite(iz), infty, kyosu::abs(z)); + auto la = eve::log10(absz); + auto r = kyosu::if_else(kyosu::is_real(z) && eve::is_positive(rz), complex(la, eve::zero(eve::as(rz))), complex(la, argz)); + if(eve::any(kyosu::is_not_finite(z))) + { + r = kyosu::if_else(eve::is_infinite(rz) && eve::is_nan(iz), complex(infty, iz), r); + } + return r; + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(log10_t, log10_); }; @@ -66,30 +86,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto log10_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(kyosu::concepts::complex) - { - auto [rz, iz] = z; - auto infty = eve::inf(eve::as(rz)); - auto arg = [](auto z){ return eve::atan2[eve::pedantic](kyosu::imag(z), kyosu::real(z));}; - auto argz = arg(z)*eve::invlog_10(eve::as(rz)); - auto absz = eve::if_else(eve::is_nan(rz) && eve::is_infinite(iz), infty, kyosu::abs(z)); - auto la = eve::log10(absz); - auto r = kyosu::if_else(kyosu::is_real(z) && eve::is_positive(rz), complex(la, eve::zero(eve::as(rz))), complex(la, argz)); - if(eve::any(kyosu::is_not_finite(z))) - { - r = kyosu::if_else(eve::is_infinite(rz) && eve::is_nan(iz), complex(infty, iz), r); - } - return r; - } - else - { - return cayley_extend(log10, z); - } - } -} diff --git a/include/kyosu/functions/log1p.hpp b/include/kyosu/functions/log1p.hpp index b515ed33..4154a288 100644 --- a/include/kyosu/functions/log1p.hpp +++ b/include/kyosu/functions/log1p.hpp @@ -19,11 +19,25 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { if constexpr(kyosu::concepts::complex) + { + auto m = kyosu::inc(z); + auto arg = [](auto zz){ return eve::atan2[eve::pedantic](kyosu::imag(zz), kyosu::real(zz));}; + auto theta = eve::if_else((kyosu::is_real(m) && eve::is_nltz(kyosu::real(m))), eve::zero, arg(m)) ; + auto rz = kyosu::real(z); + auto iz2 = eve::sqr(kyosu::imag(z)); + auto r = eve::half(eve::as(theta))*eve::log1p(rz*(rz+2)+iz2); + return complex(r, theta); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(log1p_t, log1p_); }; @@ -71,24 +85,3 @@ namespace kyosu //====================================================================================================================== } -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto log1p_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(kyosu::concepts::complex) - { - auto m = kyosu::inc(z); - auto arg = [](auto zz){ return eve::atan2[eve::pedantic](kyosu::imag(zz), kyosu::real(zz));}; - auto theta = eve::if_else((kyosu::is_real(m) && eve::is_nltz(kyosu::real(m))), eve::zero, arg(m)) ; - auto rz = kyosu::real(z); - auto iz2 = eve::sqr(kyosu::imag(z)); - auto r = eve::half(eve::as(theta))*eve::log1p(rz*(rz+2)+iz2); - return complex(r, theta); - } - else - { - return cayley_extend(log1p, z); - } - } -} diff --git a/include/kyosu/functions/log2.hpp b/include/kyosu/functions/log2.hpp index 54fd6a81..60d8e4aa 100644 --- a/include/kyosu/functions/log2.hpp +++ b/include/kyosu/functions/log2.hpp @@ -19,14 +19,34 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(kyosu::concepts::complex) + { + auto [rz, iz] = z; + auto infty = eve::inf(eve::as(rz)); + auto arg = [](auto z){ return eve::atan2[eve::pedantic](kyosu::imag(z), kyosu::real(z));}; + auto argz = arg(z)*eve::invlog_2(eve::as(rz)); + auto absz = eve::if_else(eve::is_nan(rz) && eve::is_infinite(iz), infty, kyosu::abs(z)); + auto la = eve::log2(absz); + auto r = kyosu::if_else(kyosu::is_real(z) && eve::is_positive(rz), complex(la), complex(la, argz)); + if(eve::any(kyosu::is_not_finite(z))) + { + r = kyosu::if_else(eve::is_infinite(rz) && eve::is_nan(iz), complex(infty, iz), r); + } + return r; + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(log2_t, log2_); -}; + }; //====================================================================================================================== //! @addtogroup functions @@ -68,30 +88,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto log2_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(kyosu::concepts::complex) - { - auto [rz, iz] = z; - auto infty = eve::inf(eve::as(rz)); - auto arg = [](auto z){ return eve::atan2[eve::pedantic](kyosu::imag(z), kyosu::real(z));}; - auto argz = arg(z)*eve::invlog_2(eve::as(rz)); - auto absz = eve::if_else(eve::is_nan(rz) && eve::is_infinite(iz), infty, kyosu::abs(z)); - auto la = eve::log2(absz); - auto r = kyosu::if_else(kyosu::is_real(z) && eve::is_positive(rz), complex(la), complex(la, argz)); - if(eve::any(kyosu::is_not_finite(z))) - { - r = kyosu::if_else(eve::is_infinite(rz) && eve::is_nan(iz), complex(infty, iz), r); - } - return r; - } - else - { - return cayley_extend(log2, z); - } - } -} diff --git a/include/kyosu/functions/log_abs.hpp b/include/kyosu/functions/log_abs.hpp index 5e549e0a..0f385397 100644 --- a/include/kyosu/functions/log_abs.hpp +++ b/include/kyosu/functions/log_abs.hpp @@ -19,7 +19,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr as_real_type_t operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::half(kyosu::as>())*eve::log(kyosu::sqr_abs(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -67,12 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto log_abs_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::half(kyosu::as>())*eve::log(kyosu::sqr_abs(z)); - } -} diff --git a/include/kyosu/functions/log_abs_gamma.hpp b/include/kyosu/functions/log_abs_gamma.hpp index 76a9263f..c3f9e7b6 100644 --- a/include/kyosu/functions/log_abs_gamma.hpp +++ b/include/kyosu/functions/log_abs_gamma.hpp @@ -19,11 +19,11 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr as_real_type_t operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return log_abs(tgamma(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(log_abs_gamma_t, log_abs_gamma_); }; @@ -66,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto log_abs_gamma_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return log_abs(tgamma(z)); - } -} diff --git a/include/kyosu/functions/log_gamma.hpp b/include/kyosu/functions/log_gamma.hpp index 4a8b6c49..63bb7d3d 100644 --- a/include/kyosu/functions/log_gamma.hpp +++ b/include/kyosu/functions/log_gamma.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(log_gamma_t, log_gamma_); }; diff --git a/include/kyosu/functions/lpnorm.hpp b/include/kyosu/functions/lpnorm.hpp index 3d905d18..db370c9f 100644 --- a/include/kyosu/functions/lpnorm.hpp +++ b/include/kyosu/functions/lpnorm.hpp @@ -18,7 +18,10 @@ namespace kyosu template requires(concepts::real

, concepts::cayley_dickson || (concepts::cayley_dickson || ...)) KYOSU_FORCEINLINE constexpr auto operator()(P p, Z1 const & z1, Zs const & ...zs) const noexcept -> decltype(eve::lpnorm(p, real(z1), real(zs)...)) - { return KYOSU_CALL(p,z1,zs...); } + { + if constexpr(sizeof...(zs) == 0) return kyosu::abs(z1); + else return eve::lpnorm(p, kyosu::abs(z1), kyosu::abs(zs)...); + } template KYOSU_FORCEINLINE constexpr auto operator()(P p, V1 v1, Vs... vs) const noexcept -> decltype(eve::lpnorm(p, real(v1), real(vs)...)) @@ -67,14 +70,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto lpnorm_(KYOSU_DELAY(), O const&, P p, Z1 z1, Zs... zs) noexcept - -> decltype(eve::lpnorm(p, real(z1), real(zs)...)) - { - if constexpr(sizeof...(zs) == 0) return kyosu::abs(z1); - else return eve::lpnorm(p, kyosu::abs(z1), kyosu::abs(zs)...); - } -} diff --git a/include/kyosu/functions/manhattan.hpp b/include/kyosu/functions/manhattan.hpp index b192a8ca..99533cf7 100644 --- a/include/kyosu/functions/manhattan.hpp +++ b/include/kyosu/functions/manhattan.hpp @@ -20,13 +20,13 @@ namespace kyosu KYOSU_FORCEINLINE constexpr auto operator()(Z0 z0, Zs... zs) const noexcept -> decltype(eve::manhattan(real(z0), real(zs)...)) { - return KYOSU_CALL(z0, zs...); + return eve::manhattan[this->options()](kumi::flatten(kumi::make_tuple(z0, zs...))); } template auto operator()(T0 t0, Ts... ts) const noexcept -> decltype( eve::manhattan(t0, ts...)) { - return eve::manhattan(t0, ts...); + return eve::manhattan[this->options()](t0, ts...); } KYOSU_CALLABLE_OBJECT(manhattan_t, manhattan_); @@ -72,15 +72,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto manhattan_(KYOSU_DELAY(), O const& o, Z0 const& z0, Zs const& ...zs) noexcept - { - if constexpr(concepts::cayley_dickson || (concepts::cayley_dickson || ...) ) - return eve::manhattan[o](kumi::flatten(kumi::make_tuple(z0, zs...))); - else - return eve::manhattan[o](z0, zs...); - } -} diff --git a/include/kyosu/functions/maxabs.hpp b/include/kyosu/functions/maxabs.hpp index 03efe42b..5d9b9ee8 100644 --- a/include/kyosu/functions/maxabs.hpp +++ b/include/kyosu/functions/maxabs.hpp @@ -20,11 +20,11 @@ namespace kyosu requires(concepts::cayley_dickson || (concepts::cayley_dickson|| ...)) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const & z0, Zs const & ... zs) const noexcept -> decltype(eve::maxabs(real(z0), real(zs)...)) - { return KYOSU_CALL(z0,zs...); } + { return eve::sqrt(eve::max[this->options()](kyosu::sqr_abs(z0), kyosu::sqr_abs(zs)...)); } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, Vs... vs) const noexcept -> decltype( eve::maxabs(v0, vs...)) - { return eve::maxabs[Options()](v0,vs...); } + { return eve::maxabs[this->options()](v0,vs...); } KYOSU_CALLABLE_OBJECT(maxabs_t, maxabs_); }; @@ -67,12 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto maxabs_(KYOSU_DELAY(), O const& o, Z0 z0, ZS... zs) noexcept - { - return eve::max[o](kyosu::abs(z0), kyosu::abs(zs)...); - } -} diff --git a/include/kyosu/functions/maxmag.hpp b/include/kyosu/functions/maxmag.hpp index 97f7f3dc..4654ffbb 100644 --- a/include/kyosu/functions/maxmag.hpp +++ b/include/kyosu/functions/maxmag.hpp @@ -16,10 +16,25 @@ namespace kyosu template struct maxmag_t : eve::strict_elementwise_callable { - template - requires(concepts::cayley_dickson || (concepts::cayley_dickson || ...)) - KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Zs const & ...zs) const noexcept -> decltype(z0 + (zs +...)) - { return KYOSU_CALL(z0,zs...); } + template + requires(concepts::cayley_dickson || concepts::cayley_dickson || (concepts::cayley_dickson || ...)) + KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const& z1, Zs const & ...zs) const noexcept -> kyosu::as_cayley_dickson_t + { + if constexpr(sizeof...(Zs) == 0) + { + auto az0 = kyosu::sqr_abs(z0); + auto az1 = kyosu::sqr_abs(z1); + auto tmp = kyosu::if_else(eve::is_not_greater_equal(az0, az1), z1, z0); + return kyosu::if_else(eve::is_not_greater_equal(az1, az0), z0, tmp); + } + else + { + using r_t = kyosu::as_cayley_dickson_t; + r_t that((*this)(z0, z1)); + ((that = (*this)(that, zs)), ...); + return that; + } + } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, Vs ... vs) const noexcept -> decltype(eve::maxmag(v0,vs...)) @@ -66,25 +81,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto maxmag_(KYOSU_DELAY(), O const&, Z0 z0, Z1 z1, Zs ... zs) noexcept - { - if constexpr(sizeof...(zs) == 0) - { - auto az0 = kyosu::sqr_abs(z0); - auto az1 = kyosu::sqr_abs(z1); - auto tmp = kyosu::if_else(eve::is_not_greater_equal(az0, az1), z1, z0); - return kyosu::if_else(eve::is_not_greater_equal(az1, az0), z0, tmp); - } - else - { - using r_t = kyosu::as_cayley_dickson_t; - r_t that(maxmag(z0, z1)); - ((that = maxmag(that, zs)), ...); - return that; - } - } -} diff --git a/include/kyosu/functions/minabs.hpp b/include/kyosu/functions/minabs.hpp index 8e7e0fbb..554e1ec7 100644 --- a/include/kyosu/functions/minabs.hpp +++ b/include/kyosu/functions/minabs.hpp @@ -20,12 +20,12 @@ namespace kyosu requires(concepts::cayley_dickson || (concepts::cayley_dickson || ...)) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Zs const & ... zs) const noexcept -> decltype(eve::minabs(real(z0), real(zs)...)) - { return KYOSU_CALL(z0,zs...); } + { return eve::sqrt(eve::min[this->options()](kyosu::sqr_abs(z0), kyosu::sqr_abs(zs)...)); } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, Vs ...vs) const noexcept -> decltype( eve::minabs(v0, vs...)) - { return eve::minabs[Options()](v0,vs...); } + { return eve::minabs[this->options()](v0,vs...); } KYOSU_CALLABLE_OBJECT(minabs_t, minabs_); }; @@ -68,12 +68,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto minabs_(KYOSU_DELAY(), O const& o, Z0 z0, Zs... zs) noexcept - { - return eve::min[o](kyosu::abs(z0), kyosu::abs(zs)...); - } -} diff --git a/include/kyosu/functions/minmag.hpp b/include/kyosu/functions/minmag.hpp index 1b390926..c08392e3 100644 --- a/include/kyosu/functions/minmag.hpp +++ b/include/kyosu/functions/minmag.hpp @@ -16,10 +16,25 @@ namespace kyosu template struct minmag_t : eve::strict_elementwise_callable { - template - requires(concepts::cayley_dickson || (concepts::cayley_dickson || ...)) - KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Zs const & ...zs) const noexcept -> decltype(z0 + (zs +...)) - { return KYOSU_CALL(z0,zs...); } + template + requires(concepts::cayley_dickson || concepts::cayley_dickson || (concepts::cayley_dickson || ...)) + KYOSU_FORCEINLINE constexpr auto operator()(C0 const& c0, C1 const& c1, Cs const & ...cs) const noexcept -> kyosu::as_cayley_dickson_t + { + if constexpr(sizeof...(cs) == 0) + { + auto ac0 = kyosu::sqr_abs(c0); + auto ac1 = kyosu::sqr_abs(c1); + auto tmp = kyosu::if_else(eve::is_not_greater_equal(ac1, ac0), c1, c0); + return kyosu::if_else(eve::is_not_greater_equal(ac0, ac1), c0, tmp); + } + else + { + using r_t = kyosu::as_cayley_dickson_t; + r_t that(minmag(c0, c1)); + ((that = minmag(that, cs)), ...); + return that; + } + } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, Vs... vs) const noexcept -> decltype(eve::minmag(v0,vs...)) @@ -66,25 +81,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto minmag_(KYOSU_DELAY(), O const&, C0 c0, C1 c1, Cs... cs) noexcept - { - if constexpr(sizeof...(cs) == 0) - { - auto ac0 = kyosu::sqr_abs(c0); - auto ac1 = kyosu::sqr_abs(c1); - auto tmp = kyosu::if_else(eve::is_not_greater_equal(ac1, ac0), c1, c0); - return kyosu::if_else(eve::is_not_greater_equal(ac0, ac1), c0, tmp); - } - else - { - using r_t = kyosu::as_cayley_dickson_t; - r_t that(minmag(c0, c1)); - ((that = minmag(that, cs)), ...); - return that; - } - } -} diff --git a/include/kyosu/functions/minus.hpp b/include/kyosu/functions/minus.hpp index 1f459eb6..1515fd57 100644 --- a/include/kyosu/functions/minus.hpp +++ b/include/kyosu/functions/minus.hpp @@ -16,7 +16,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return -z; } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,12 +64,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto minus_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return -z; - } -} diff --git a/include/kyosu/functions/muli.hpp b/include/kyosu/functions/muli.hpp index 04c4141c..4d55a762 100644 --- a/include/kyosu/functions/muli.hpp +++ b/include/kyosu/functions/muli.hpp @@ -16,12 +16,19 @@ namespace kyosu struct muli_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z const& c) const noexcept + { + if constexpr(kyosu::concepts::complex) + return Z(-ipart(c), real(c)); + else if constexpr(kyosu::concepts::quaternion) + return Z(-ipart(c), real(c), -kpart(c), jpart(c)); + else + return kyosu::i(as(c))*c; + } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(v); } + { return complex(zero(as(v)), v); } KYOSU_CALLABLE_OBJECT(muli_t, muli_); }; @@ -67,17 +74,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto muli_(KYOSU_DELAY(), O const&, Z c) noexcept - { - if constexpr(kyosu::concepts::complex) - return Z(-ipart(c), real(c)); - else if constexpr(kyosu::concepts::quaternion) - return Z(-ipart(c), real(c), -kpart(c), jpart(c)); - else - return kyosu::i(as(c))*c; - } -} diff --git a/include/kyosu/functions/mulmi.hpp b/include/kyosu/functions/mulmi.hpp index 76aad0fc..1bc02b3a 100644 --- a/include/kyosu/functions/mulmi.hpp +++ b/include/kyosu/functions/mulmi.hpp @@ -16,12 +16,19 @@ namespace kyosu struct mulmi_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z const& c) const noexcept + { + if constexpr(kyosu::concepts::complex) + return Z(ipart(c), -real(c)); + else if constexpr(kyosu::concepts::quaternion) + return Z(ipart(c), -real(c), kpart(c), -jpart(c)); + else + return mi(as(c))*c; + } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(v); } + { return complex(zero(as(v)), -v); } KYOSU_CALLABLE_OBJECT(mulmi_t, mulmi_); }; @@ -67,17 +74,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto mulmi_(KYOSU_DELAY(), O const&, Z c) noexcept - { - if constexpr(kyosu::concepts::complex) - return Z(ipart(c), -real(c)); - else if constexpr(kyosu::concepts::quaternion) - return Z(ipart(c), -real(c), kpart(c), -jpart(c)); - else - return mi(as(c))*c; - } -} diff --git a/include/kyosu/functions/nearest.hpp b/include/kyosu/functions/nearest.hpp index 566f473a..c8e67234 100644 --- a/include/kyosu/functions/nearest.hpp +++ b/include/kyosu/functions/nearest.hpp @@ -16,7 +16,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return Z{kumi::map([](auto const& e) { return eve::nearest(e); }, z)}; } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto nearest_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return Z{kumi::map([](auto const& e) { return eve::nearest(e); }, c)}; - } -} diff --git a/include/kyosu/functions/negmaxabs.hpp b/include/kyosu/functions/negmaxabs.hpp index 487ee224..24e3f2fc 100644 --- a/include/kyosu/functions/negmaxabs.hpp +++ b/include/kyosu/functions/negmaxabs.hpp @@ -20,12 +20,12 @@ namespace kyosu requires(concepts::cayley_dickson || (concepts::cayley_dickson|| ...)) KYOSU_FORCEINLINE constexpr auto operator()(Z0 const & z0, Zs const & ... zs) const noexcept -> decltype(eve::negmaxabs(real(z0), real(zs)...)) - { return eve::minus(kyosu::maxabs[Options()](z0, zs...)); } + { return eve::minus(kyosu::maxabs[this->options()](z0, zs...)); } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, Vs... vs) const noexcept -> decltype( eve::negmaxabs(v0, vs...)) - { return eve::negmaxabs[Options()](v0,vs...); } + { return eve::negmaxabs[this->options()](v0,vs...); } KYOSU_CALLABLE_OBJECT(negmaxabs_t, negmaxabs_); }; diff --git a/include/kyosu/functions/negminabs.hpp b/include/kyosu/functions/negminabs.hpp index 8fcf3b60..c7a50900 100644 --- a/include/kyosu/functions/negminabs.hpp +++ b/include/kyosu/functions/negminabs.hpp @@ -21,13 +21,13 @@ namespace kyosu KYOSU_FORCEINLINE constexpr auto operator()(Z0 const & z0, Zs const & ... zs) const noexcept -> decltype(eve::negminabs(real(z0), real(zs)...)) { - return eve::minus(minabs[Options()](z0, zs...)); + return eve::minus(minabs[this->options()](z0, zs...)); } template KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, Vs... vs) const noexcept -> decltype( eve::negminabs(v0, vs...)) - { return eve::negminabs[Options()](v0,vs...); } + { return eve::negminabs[this->options()](v0,vs...); } KYOSU_CALLABLE_OBJECT(negminabs_t, negminabs_); }; diff --git a/include/kyosu/functions/oneminus.hpp b/include/kyosu/functions/oneminus.hpp index be72fc28..cae4a33d 100644 --- a/include/kyosu/functions/oneminus.hpp +++ b/include/kyosu/functions/oneminus.hpp @@ -19,7 +19,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return inc(minus(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -67,12 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr Z oneminus_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::inc(-z); - } -} diff --git a/include/kyosu/functions/pow.hpp b/include/kyosu/functions/pow.hpp index 891e812a..2cfb4245 100644 --- a/include/kyosu/functions/pow.hpp +++ b/include/kyosu/functions/pow.hpp @@ -36,7 +36,7 @@ namespace kyosu template requires(!eve::integral_value) KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept ->complex_t - { return KYOSU_CALL(complex(v0),v1); } + { return (*this)(complex(v0),v1); } KYOSU_CALLABLE_OBJECT(pow_t, pow_); }; diff --git a/include/kyosu/functions/pow_abs.hpp b/include/kyosu/functions/pow_abs.hpp index 36759f17..c936085f 100644 --- a/include/kyosu/functions/pow_abs.hpp +++ b/include/kyosu/functions/pow_abs.hpp @@ -17,21 +17,25 @@ namespace kyosu { template requires(concepts::cayley_dickson || concepts::cayley_dickson) - KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1) const noexcept //-> decltype(z0+z1) - { return KYOSU_CALL(z0,z1); } + KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1) const noexcept + -> decltype(kyosu::abs(z0)+z1) + { + if constexpr(kyosu::concepts::real) + return eve::pow(kyosu::sqr_abs(z0), z1*eve::half(eve::as(z1))); + else + return kyosu::pow(kyosu::abs(z0), z1); + } template requires(!eve::integral_value) - KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept //-> decltype(v0+v1) + KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept + -> decltype(eve::pow_abs(v0,v1)) { return eve::pow_abs(v0,v1); } template - KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept //-> decltype(v0+v1) - { return eve::pow(eve::abs(v0),v1); } - -// template -// KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1) const noexcept //-> decltype(v0+v1) -// { return eve::pow_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_); }; @@ -75,15 +79,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto pow_abs_(KYOSU_DELAY(), O const&, Z0 c0, Z1 c1) noexcept - { - if constexpr(kyosu::concepts::real) - return eve::pow(kyosu::sqr_abs(c0), c1*eve::half(eve::as(c1))); - else - return kyosu::pow(abs(c0), c1); - } -} diff --git a/include/kyosu/functions/pure.hpp b/include/kyosu/functions/pure.hpp index 8f00c035..2297e355 100644 --- a/include/kyosu/functions/pure.hpp +++ b/include/kyosu/functions/pure.hpp @@ -15,10 +15,15 @@ namespace kyosu struct pure_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z z) const noexcept + { + real(z) = 0; + return z; + } template - KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return KYOSU_CALL(v); } + KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept + { return V{0}; } KYOSU_CALLABLE_OBJECT(pure_t, pure_); }; @@ -63,17 +68,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto pure_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::cayley_dickson) - { - real(z) = 0; - return z; - } - else return Z{0}; - } -} diff --git a/include/kyosu/functions/radinpi.hpp b/include/kyosu/functions/radinpi.hpp index 50a303b4..8e90fa49 100644 --- a/include/kyosu/functions/radinpi.hpp +++ b/include/kyosu/functions/radinpi.hpp @@ -16,8 +16,8 @@ namespace kyosu struct radinpi_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z const& a) const noexcept + { return inv_pi(eve::as(a))*a; } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto radinpi_(KYOSU_DELAY(), O const&, Z a) noexcept - { - return inv_pi(eve::as(a))*a; - } -} diff --git a/include/kyosu/functions/rec.hpp b/include/kyosu/functions/rec.hpp index aadae32a..fe44c21c 100644 --- a/include/kyosu/functions/rec.hpp +++ b/include/kyosu/functions/rec.hpp @@ -19,8 +19,10 @@ namespace kyosu struct rec_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z const& c) const noexcept + { + return if_else(is_infinite(c), eve::zero, if_else(is_eqz(c), Z(eve::rec(real(c))), conj(c)/sqr_abs(c))); + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -68,12 +70,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto rec_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return if_else(is_infinite(c), eve::zero, if_else(is_eqz(c), Z(eve::rec(real(c))), conj(c)/sqr_abs(c))); - } -} diff --git a/include/kyosu/functions/reldist.hpp b/include/kyosu/functions/reldist.hpp index 0e6c2f6a..0981f4d4 100644 --- a/include/kyosu/functions/reldist.hpp +++ b/include/kyosu/functions/reldist.hpp @@ -24,13 +24,9 @@ namespace kyosu auto d = dist(c0, c1); auto r = d/eve::max(kyosu::abs(c0), kyosu::abs(c1), eve::one(eve::as(abs(c0)))); if (Options::contains(eve::numeric)) - { return if_else (kyosu::is_equal(c0, c1) || (kyosu::is_nan(c0) && kyosu::is_nan(c1)), zero, r); - } else - { return r; - } } template @@ -39,13 +35,9 @@ namespace kyosu auto d = dist(c0, c1); auto r = d/eve::max(kyosu::abs(c0), kyosu::abs(c1), eve::one(eve::as(abs(c0)))); if (Options::contains(eve::numeric)) - { return if_else (is_equal(c0, c1) || (is_nan(c0) && is_nan(c1)), zero, r); - } else - { return r; - } } KYOSU_CALLABLE_OBJECT(reldist_t, reldist_); diff --git a/include/kyosu/functions/sec.hpp b/include/kyosu/functions/sec.hpp index ae50b845..20807977 100644 --- a/include/kyosu/functions/sec.hpp +++ b/include/kyosu/functions/sec.hpp @@ -8,6 +8,8 @@ #pragma once #include "eve/traits/as_logical.hpp" #include +#include +#include namespace kyosu { @@ -16,7 +18,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::rec(kyosu::cos(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sec_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::rec(kyosu::cos(z)); - } -} diff --git a/include/kyosu/functions/sech.hpp b/include/kyosu/functions/sech.hpp index 49d1384b..de2c3ab1 100644 --- a/include/kyosu/functions/sech.hpp +++ b/include/kyosu/functions/sech.hpp @@ -8,6 +8,8 @@ #pragma once #include "eve/traits/as_logical.hpp" #include +#include +#include namespace kyosu { @@ -16,7 +18,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::rec(kyosu::cosh(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sech_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::rec(kyosu::cosh(z)); - } -} diff --git a/include/kyosu/functions/secpi.hpp b/include/kyosu/functions/secpi.hpp index 1e930c95..a011c6c6 100644 --- a/include/kyosu/functions/secpi.hpp +++ b/include/kyosu/functions/secpi.hpp @@ -8,7 +8,7 @@ #pragma once #include "eve/traits/as_logical.hpp" #include -#include +#include #include namespace kyosu @@ -18,7 +18,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return kyosu::rec(kyosu::cospi(z)); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -66,12 +66,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto secpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - return kyosu::rec(kyosu::cospi(z)); - } -} diff --git a/include/kyosu/functions/sign.hpp b/include/kyosu/functions/sign.hpp index 18076cc0..b1975fc8 100644 --- a/include/kyosu/functions/sign.hpp +++ b/include/kyosu/functions/sign.hpp @@ -6,9 +6,9 @@ */ //====================================================================================================================== #pragma once -#include "eve/traits/as_logical.hpp" #include #include +#include namespace kyosu { @@ -16,8 +16,8 @@ namespace kyosu struct sign_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z const& c) const noexcept + { return kyosu::if_else(kyosu::is_nez(c), c/abs(c), eve::zero); } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sign_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kyosu::if_else(kyosu::is_nez(c), c/abs(c), eve::zero); - } -} diff --git a/include/kyosu/functions/signnz.hpp b/include/kyosu/functions/signnz.hpp index e7cd0ec4..df880b76 100644 --- a/include/kyosu/functions/signnz.hpp +++ b/include/kyosu/functions/signnz.hpp @@ -16,8 +16,8 @@ namespace kyosu struct signnz_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z const& c) const noexcept + { return kyosu::if_else(kyosu::is_nez(c), c/abs(c), Z(eve::signnz(real(c))));; } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -67,12 +67,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto signnz_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return kyosu::if_else(kyosu::is_nez(c), c/abs(c), Z(eve::signnz(real(c)))); - } -} diff --git a/include/kyosu/functions/sin.hpp b/include/kyosu/functions/sin.hpp index 64d0b54e..efa54d6a 100644 --- a/include/kyosu/functions/sin.hpp +++ b/include/kyosu/functions/sin.hpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include namespace kyosu { @@ -18,7 +20,12 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + return muli(kyosu::sinh(Z(mulmi(z)))); + else + return kyosu::_::cayley_extend(*this, z); + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -73,20 +80,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sin_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto s = kyosu::sinh(Z(-kyosu::imag(z), kyosu::real(z))); - return Z(kyosu::imag(s), -kyosu::real(s)); - } - else - { - return cayley_extend(sin, z); - } - } -} diff --git a/include/kyosu/functions/sinc.hpp b/include/kyosu/functions/sinc.hpp index b6445c36..0c80604f 100644 --- a/include/kyosu/functions/sinc.hpp +++ b/include/kyosu/functions/sinc.hpp @@ -17,7 +17,18 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto s = kyosu::sin(z); + using u_t = eve::underlying_type_t; + return kyosu::if_else(kyosu::abs(z) < eve::eps(eve::as(u_t())), eve::one(eve::as(u_t())), s/z); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,21 +76,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sinc_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto s = kyosu::sin(z); - using u_t = eve::underlying_type_t; - return kyosu::if_else(kyosu::abs(z) < eve::eps(eve::as(u_t())), eve::one(eve::as(u_t())), s/z); - } - else - { - return cayley_extend(sinc, z); - } - } -} diff --git a/include/kyosu/functions/sincos.hpp b/include/kyosu/functions/sincos.hpp index 7dce8476..d8742f24 100644 --- a/include/kyosu/functions/sincos.hpp +++ b/include/kyosu/functions/sincos.hpp @@ -9,6 +9,8 @@ #include "eve/traits/as_logical.hpp" #include #include +#include +#include #include namespace kyosu @@ -18,7 +20,18 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr kumi::tuple operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto [sh, ch] = sinhcosh(muli(z)); + return kumi::tuple{mulmi(sh), ch}; + + } + else + { + return kyosu::_::cayley_extend2(*this, z); + } + } template KYOSU_FORCEINLINE constexpr kumi::tuple operator()(V v) const noexcept @@ -66,21 +79,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sincos_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto [sh, ch] = sinhcosh(Z(-kyosu::imag(z), kyosu::real(z))); - return kumi::tuple{Z(kyosu::imag(sh), -kyosu::real(sh)), ch}; - - } - else - { - return cayley_extend2(sincos, z); - } - } -} diff --git a/include/kyosu/functions/sinh.hpp b/include/kyosu/functions/sinh.hpp index 4200a0a2..f8cc793d 100644 --- a/include/kyosu/functions/sinh.hpp +++ b/include/kyosu/functions/sinh.hpp @@ -20,7 +20,33 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto [rz, iz] = z; + auto [s, c] = eve::sincos(iz); + auto [sh, ch] = eve::sinhcosh(rz); + auto r = c*sh; + auto i = s*ch; + if (eve::all(kyosu::is_finite(z))) return Z(r, i); + auto infrz = kyosu::is_infinite(rz); + auto nanrz = kyosu::is_nan(rz); + if (eve::any(infrz || nanrz)) + { + r = eve::if_else(infrz && eve::is_not_finite(iz), rz, r); + i = eve::if_else(infrz && eve::is_nan(iz), eve::allbits, i); + r = eve::if_else(nanrz, eve::allbits, r); + i = eve::if_else(nanrz, eve::allbits, i); + } + i = eve::if_else(kyosu::is_real(z), eve::zero, i); + r = eve::if_else(kyosu::is_eqz(kyosu::real(z)), eve::zero, r); + return Z(r, i); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -87,36 +113,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sinh_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto [rz, iz] = z; - auto [s, c] = eve::sincos(iz); - auto [sh, ch] = eve::sinhcosh(rz); - auto r = c*sh; - auto i = s*ch; - if (eve::all(kyosu::is_finite(z))) return Z(r, i); - auto infrz = kyosu::is_infinite(rz); - auto nanrz = kyosu::is_nan(rz); - if (eve::any(infrz || nanrz)) - { - r = eve::if_else(infrz && eve::is_not_finite(iz), rz, r); - i = eve::if_else(infrz && eve::is_nan(iz), eve::allbits, i); - r = eve::if_else(nanrz, eve::allbits, r); - i = eve::if_else(nanrz, eve::allbits, i); - } - i = eve::if_else(kyosu::is_real(z), eve::zero, i); - r = eve::if_else(kyosu::is_eqz(kyosu::real(z)), eve::zero, r); - return Z(r, i); - } - else - { - return cayley_extend(sinh, z); - } - } -} diff --git a/include/kyosu/functions/sinhc.hpp b/include/kyosu/functions/sinhc.hpp index d8128cf0..f039437f 100644 --- a/include/kyosu/functions/sinhc.hpp +++ b/include/kyosu/functions/sinhc.hpp @@ -17,7 +17,18 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto s = kyosu::sinh(z); + using u_t = eve::underlying_type_t; + return kyosu::if_else(kyosu::abs(z) < eve::eps(eve::as(u_t())), eve::one(eve::as(u_t())), s/z); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,21 +76,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sinhc_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto s = kyosu::sinh(z); - using u_t = eve::underlying_type_t; - return kyosu::if_else(kyosu::abs(z) < eve::eps(eve::as(u_t())), eve::one(eve::as(u_t())), s/z); - } - else - { - return cayley_extend(sinhc, z); - } - } -} diff --git a/include/kyosu/functions/sinhcosh.hpp b/include/kyosu/functions/sinhcosh.hpp index 49903e40..595a7273 100644 --- a/include/kyosu/functions/sinhcosh.hpp +++ b/include/kyosu/functions/sinhcosh.hpp @@ -17,11 +17,46 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr kumi::tuple operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto [rz, iz] = z; + auto [s, c] = eve::sincos(iz); + auto [sh, ch] = eve::sinhcosh(rz); + auto rs = c*sh; + auto is = s*ch; + auto infrz = eve::is_infinite(rz); + auto nanrz = eve::is_nan(rz); + if (eve::any(infrz || nanrz)) + { + rs = eve::if_else(infrz && eve::is_not_finite(iz), rz, rs); + is = eve::if_else(infrz && eve::is_nan(iz), eve::allbits, is); + rs = eve::if_else(nanrz, eve::allbits, rs); + is = eve::if_else(nanrz, eve::allbits, is); + } + is = eve::if_else(kyosu::is_real(z), eve::zero, is); + rs = eve::if_else(kyosu::is_eqz(kyosu::real(z)), eve::zero, rs); + auto ss = Z(rs, is); + + auto rc = c*ch; + auto ic = s*sh; + ic = eve::if_else(kyosu::is_eqz(kyosu::real(z)) || kyosu::is_real(z), eve::zero, ic); + auto cc = Z(rc, ic); + if (eve::any(kyosu::is_not_finite(z))) + { + cc = kyosu::if_else(infrz && is_not_finite(iz), Z(eve::inf(eve::as(rz)), eve::nan(eve::as(rz))), cc); + cc = kyosu::if_else(nanrz && is_infinite(iz), Z(eve::nan(eve::as(rz)), eve::nan(eve::as(rz))), cc); + } + return kumi::tuple{ss, cc}; + } + else + { + return kyosu::_::cayley_extend2(*this, z); + } + } template - KYOSU_FORCEINLINE constexpr kumi::tuple operator()(V v) - const noexcept + KYOSU_FORCEINLINE constexpr kumi::tuple operator()(V v) const noexcept { return eve::sinhcosh(v); } KYOSU_CALLABLE_OBJECT(sinhcosh_t, sinhcosh_); @@ -66,46 +101,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sinhcosh_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto [rz, iz] = z; - auto [s, c] = eve::sincos(iz); - auto [sh, ch] = eve::sinhcosh(rz); - auto rs = c*sh; - auto is = s*ch; - auto infrz = eve::is_infinite(rz); - auto nanrz = eve::is_nan(rz); - if (eve::any(infrz || nanrz)) - { - rs = eve::if_else(infrz && eve::is_not_finite(iz), rz, rs); - is = eve::if_else(infrz && eve::is_nan(iz), eve::allbits, is); - rs = eve::if_else(nanrz, eve::allbits, rs); - is = eve::if_else(nanrz, eve::allbits, is); - } - is = eve::if_else(kyosu::is_real(z), eve::zero, is); - rs = eve::if_else(kyosu::is_eqz(kyosu::real(z)), eve::zero, rs); - auto ss = Z(rs, is); - - auto rc = c*ch; - auto ic = s*sh; - ic = eve::if_else(kyosu::is_eqz(kyosu::real(z)) || kyosu::is_real(z), eve::zero, ic); - auto cc = Z(rc, ic); - if (eve::any(kyosu::is_not_finite(z))) - { - cc = kyosu::if_else(infrz && is_not_finite(iz), Z(eve::inf(eve::as(rz)), eve::nan(eve::as(rz))), cc); - cc = kyosu::if_else(nanrz && is_infinite(iz), Z(eve::nan(eve::as(rz)), eve::nan(eve::as(rz))), cc); - } - return kumi::tuple{ss, cc}; - } - else - { - return cayley_extend2(sinhcosh, z); - } - } -} diff --git a/include/kyosu/functions/sinpi.hpp b/include/kyosu/functions/sinpi.hpp index 4b0db1e6..9c5aed50 100644 --- a/include/kyosu/functions/sinpi.hpp +++ b/include/kyosu/functions/sinpi.hpp @@ -17,7 +17,32 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto rz = -kyosu::imag(z); + auto iz = kyosu::real(z); + rz *= eve::pi(eve::as(rz)); + auto [s, c] = eve::sinpicospi(iz); + auto [sh, ch] = eve::sinhcosh(rz); + auto r = c*sh; + auto i = s*ch; + if (eve::any(kyosu::is_not_finite(z))) + { + r = eve::if_else(eve::is_infinite(rz) && eve::is_not_finite(iz), rz, r); + i = eve::if_else(eve::is_infinite(rz) && eve::is_nan(iz), iz, i); + r = eve::if_else(eve::is_nan(rz), rz, r); + i = eve::if_else(eve::is_nan(rz), rz, i); + i = eve::if_else(kyosu::is_imag(z), eve::zero, i); + r = eve::if_else(kyosu::is_real(z), eve::zero, r); + } + return kyosu::complex(i, -r); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,35 +90,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sinpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto rz = -kyosu::imag(z); - auto iz = kyosu::real(z); - rz *= eve::pi(eve::as(rz)); - auto [s, c] = eve::sinpicospi(iz); - auto [sh, ch] = eve::sinhcosh(rz); - auto r = c*sh; - auto i = s*ch; - if (eve::any(kyosu::is_not_finite(z))) - { - r = eve::if_else(eve::is_infinite(rz) && eve::is_not_finite(iz), rz, r); - i = eve::if_else(eve::is_infinite(rz) && eve::is_nan(iz), iz, i); - r = eve::if_else(eve::is_nan(rz), rz, r); - i = eve::if_else(eve::is_nan(rz), rz, i); - i = eve::if_else(kyosu::is_imag(z), eve::zero, i); - r = eve::if_else(kyosu::is_real(z), eve::zero, r); - } - return kyosu::complex(i, -r); - } - else - { - return cayley_extend(sinpi, z); - } - } -} diff --git a/include/kyosu/functions/sinpicospi.hpp b/include/kyosu/functions/sinpicospi.hpp index 27e6f195..e0e0ef2b 100644 --- a/include/kyosu/functions/sinpicospi.hpp +++ b/include/kyosu/functions/sinpicospi.hpp @@ -17,7 +17,47 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr kumi::tuple operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto [rz, iz] = z; + iz *= eve::pi(eve::as(iz)); + auto [s, c] = eve::sinpicospi(rz); + auto [sh, ch] = eve::sinhcosh(iz); + auto rc = c*ch; + auto ic = eve::if_else(kyosu::is_imag(z) || kyosu::is_real(z), eve::zero, -s*sh); + if (eve::any(kyosu::is_not_finite(z))) + { + rc = eve::if_else(eve::is_infinite(iz) && eve::is_not_finite(rz), eve::inf(eve::as(rc)), rc); + ic = eve::if_else(eve::is_infinite(iz) && eve::is_not_finite(rz), eve::allbits, ic); + rc = eve::if_else(eve::is_nan(iz) && eve::is_infinite(rz), eve::allbits, rc); + ic = eve::if_else(eve::is_nan(iz) && eve::is_infinite(rz), eve::allbits, ic); + } + auto cpi = kyosu::complex(rc, ic); + auto arz = -kyosu::imag(z); + auto aiz = kyosu::real(z); + arz*= eve::pi(eve::as(arz)); + auto [as, ac] = eve::sinpicospi(aiz); + auto [ash, ach] = eve::sinhcosh(arz); + auto rs = ac*ash; + auto is = as*ach; + if (eve::any(kyosu::is_not_finite(z))) + { + rs = eve::if_else(eve::is_infinite(aiz) && eve::is_not_finite(arz), arz, rs); + is = eve::if_else(eve::is_infinite(aiz) && eve::is_nan(arz), iz, is); + rs = eve::if_else(eve::is_nan(aiz), arz, rs); + is = eve::if_else(eve::is_nan(aiz), arz, is); + is = eve::if_else(eve::is_eqz(aiz), eve::zero, is); + rs = eve::if_else(eve::is_eqz(arz), eve::zero, rs); + } + auto spi = kyosu::complex(is, -rs); + return kumi::tuple{spi, cpi}; + } + else + { + return kyosu::_::cayley_extend2(*this, z); + } + } template KYOSU_FORCEINLINE constexpr kumi::tuple operator()(V v) const noexcept @@ -65,50 +105,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sinpicospi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto [rz, iz] = z; - iz *= eve::pi(eve::as(iz)); - auto [s, c] = eve::sinpicospi(rz); - auto [sh, ch] = eve::sinhcosh(iz); - auto rc = c*ch; - auto ic = eve::if_else(kyosu::is_imag(z) || kyosu::is_real(z), eve::zero, -s*sh); - if (eve::any(kyosu::is_not_finite(z))) - { - rc = eve::if_else(eve::is_infinite(iz) && eve::is_not_finite(rz), eve::inf(eve::as(rc)), rc); - ic = eve::if_else(eve::is_infinite(iz) && eve::is_not_finite(rz), eve::allbits, ic); - rc = eve::if_else(eve::is_nan(iz) && eve::is_infinite(rz), eve::allbits, rc); - ic = eve::if_else(eve::is_nan(iz) && eve::is_infinite(rz), eve::allbits, ic); - } - auto cpi = kyosu::complex(rc, ic); - auto arz = -kyosu::imag(z); - auto aiz = kyosu::real(z); - arz*= eve::pi(eve::as(arz)); - auto [as, ac] = eve::sinpicospi(aiz); - auto [ash, ach] = eve::sinhcosh(arz); - auto rs = ac*ash; - auto is = as*ach; - if (eve::any(kyosu::is_not_finite(z))) - { - rs = eve::if_else(eve::is_infinite(aiz) && eve::is_not_finite(arz), arz, rs); - is = eve::if_else(eve::is_infinite(aiz) && eve::is_nan(arz), iz, is); - rs = eve::if_else(eve::is_nan(aiz), arz, rs); - is = eve::if_else(eve::is_nan(aiz), arz, is); - is = eve::if_else(eve::is_eqz(aiz), eve::zero, is); - rs = eve::if_else(eve::is_eqz(arz), eve::zero, rs); - } - auto spi = kyosu::complex(is, -rs); - return kumi::tuple{spi, cpi}; - } - else - { - return cayley_extend2(sinpicospi, z); - } - } -} diff --git a/include/kyosu/functions/slerp.hpp b/include/kyosu/functions/slerp.hpp index 1d79c67e..922cef14 100644 --- a/include/kyosu/functions/slerp.hpp +++ b/include/kyosu/functions/slerp.hpp @@ -21,12 +21,23 @@ namespace kyosu { template requires((concepts::cayley_dickson || concepts::cayley_dickson)&& concepts::real) - KYOSU_FORCEINLINE constexpr auto operator()(Z0 const& z0, Z1 const & z1, Z2 const & z2) const noexcept -> decltype(z0+z1+z2) - { return KYOSU_CALL(z0,z1,z2); } + KYOSU_FORCEINLINE constexpr auto operator()(Z0 z0, Z1 z1, Z2 z2) const noexcept + -> decltype(z0+z1+z2) + { + if constexpr(!Options::contains(assume_unitary)) + { + z0 = kyosu::signnz(z0); + z1 = kyosu::signnz(z1); + } + auto gez = eve::is_gez(real(kyosu::dot(z0, z1))); + auto mix = kyosu::if_else(gez, z1, -z1); + return z1*kyosu::pow(kyosu::conj(z1)*mix, z2); + } template - KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept -> decltype(complex(v0)+complex(v1)+v2) - { return KYOSU_CALL(complex(v0),complex(v1),v2); } + KYOSU_FORCEINLINE constexpr auto operator()(V0 v0, V1 v1, V2 v2) const noexcept + -> decltype(complex(v0)+complex(v1)+v2) + { return (*this)(complex(v0),complex(v1),v2); } KYOSU_CALLABLE_OBJECT(slerp_t, slerp_); }; @@ -73,19 +84,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto slerp_(KYOSU_DELAY(), O const&, Z1 z1, Z2 z2, T t) noexcept - { - if constexpr(!O::contains(assume_unitary)) - { - z1 = signnz(z1); - z2 = signnz(z2); - } - auto gez = eve::is_gez(real(kyosu::dot(z1, z2))); - auto mix = kyosu::if_else(gez, z2, -z2); - return z1*kyosu::pow(kyosu::conj(z1)*mix, t); - } -} diff --git a/include/kyosu/functions/sph_bessel_h1_0.hpp b/include/kyosu/functions/sph_bessel_h1_0.hpp index 82101c8a..639a7e74 100644 --- a/include/kyosu/functions/sph_bessel_h1_0.hpp +++ b/include/kyosu/functions/sph_bessel_h1_0.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_h1_0_t, sph_bessel_h1_0_); }; diff --git a/include/kyosu/functions/sph_bessel_h1_1.hpp b/include/kyosu/functions/sph_bessel_h1_1.hpp index 0001d185..c04949d8 100644 --- a/include/kyosu/functions/sph_bessel_h1_1.hpp +++ b/include/kyosu/functions/sph_bessel_h1_1.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_h1_1_t, sph_bessel_h1_1_); }; diff --git a/include/kyosu/functions/sph_bessel_h2_0.hpp b/include/kyosu/functions/sph_bessel_h2_0.hpp index 69f5c91c..a9e04de1 100644 --- a/include/kyosu/functions/sph_bessel_h2_0.hpp +++ b/include/kyosu/functions/sph_bessel_h2_0.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_h2_0_t, sph_bessel_h2_0_); }; diff --git a/include/kyosu/functions/sph_bessel_h2_1.hpp b/include/kyosu/functions/sph_bessel_h2_1.hpp index 268b6635..a0504313 100644 --- a/include/kyosu/functions/sph_bessel_h2_1.hpp +++ b/include/kyosu/functions/sph_bessel_h2_1.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_h2_1_t, sph_bessel_h2_1_); }; diff --git a/include/kyosu/functions/sph_bessel_i1_0.hpp b/include/kyosu/functions/sph_bessel_i1_0.hpp index bcb56a87..0c87b69e 100644 --- a/include/kyosu/functions/sph_bessel_i1_0.hpp +++ b/include/kyosu/functions/sph_bessel_i1_0.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_i1_0_t, sph_bessel_i1_0_); }; diff --git a/include/kyosu/functions/sph_bessel_i1_1.hpp b/include/kyosu/functions/sph_bessel_i1_1.hpp index 8100d4bf..fd97582c 100644 --- a/include/kyosu/functions/sph_bessel_i1_1.hpp +++ b/include/kyosu/functions/sph_bessel_i1_1.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_i1_1_t, sph_bessel_i1_1_); }; diff --git a/include/kyosu/functions/sph_bessel_i2_0.hpp b/include/kyosu/functions/sph_bessel_i2_0.hpp index eb64013a..e4068f21 100644 --- a/include/kyosu/functions/sph_bessel_i2_0.hpp +++ b/include/kyosu/functions/sph_bessel_i2_0.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_i2_0_t, sph_bessel_i2_0_); }; diff --git a/include/kyosu/functions/sph_bessel_i2_1.hpp b/include/kyosu/functions/sph_bessel_i2_1.hpp index 03cdd6a8..d1492207 100644 --- a/include/kyosu/functions/sph_bessel_i2_1.hpp +++ b/include/kyosu/functions/sph_bessel_i2_1.hpp @@ -19,7 +19,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_i2_1_t, sph_bessel_i2_1_); }; diff --git a/include/kyosu/functions/sph_bessel_k0.hpp b/include/kyosu/functions/sph_bessel_k0.hpp index 1fa30f8c..89c0d9ec 100644 --- a/include/kyosu/functions/sph_bessel_k0.hpp +++ b/include/kyosu/functions/sph_bessel_k0.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_k0_t, sph_bessel_k0_); }; diff --git a/include/kyosu/functions/sph_bessel_k1.hpp b/include/kyosu/functions/sph_bessel_k1.hpp index 8afeaae9..b62d6d70 100644 --- a/include/kyosu/functions/sph_bessel_k1.hpp +++ b/include/kyosu/functions/sph_bessel_k1.hpp @@ -20,7 +20,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sph_bessel_k1_t, sph_bessel_k1_); }; diff --git a/include/kyosu/functions/sqr.hpp b/include/kyosu/functions/sqr.hpp index a4b0c44a..0cac9333 100644 --- a/include/kyosu/functions/sqr.hpp +++ b/include/kyosu/functions/sqr.hpp @@ -15,8 +15,23 @@ namespace kyosu struct sqr_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr Z operator()(Z c) const noexcept + { + if constexpr(kyosu::dimension_v <= 2) + { + return c*c; + } + else + { + auto squares = kumi::map_index([](I, auto const& m) + { constexpr auto sgn = (I::value == 0)-(I::value > 0); + return sgn*m*m; }, c); + auto r = kumi::sum( squares, 0); + auto a = 2*real(c); + real(c) = 0; + return r+a*c; + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -64,25 +79,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sqr_(KYOSU_DELAY(), O const&, Z c) noexcept - { - if constexpr(kyosu::dimension_v <= 2) - { - return c*c; - } - else - { - auto squares = kumi::map_index([](I, auto const& m) - { constexpr auto sgn = (I::value == 0)-(I::value > 0); - return sgn*m*m; }, c); - auto r = kumi::sum( squares, 0); - auto a = 2*real(c); - real(c) = 0; - return r+a*c; - } - } -} diff --git a/include/kyosu/functions/sqr_abs.hpp b/include/kyosu/functions/sqr_abs.hpp index 976050c7..aa1c820e 100644 --- a/include/kyosu/functions/sqr_abs.hpp +++ b/include/kyosu/functions/sqr_abs.hpp @@ -15,10 +15,17 @@ namespace kyosu struct sqr_abs_t : eve::elementwise_callable { template - KYOSU_FORCEINLINE constexpr as_real_type_t operator()(Z z) const noexcept { return KYOSU_CALL(z); } + KYOSU_FORCEINLINE constexpr as_real_type_t operator()(Z v) const noexcept + { + auto anyinf = kumi::any_of(v, eve::is_infinite); + auto squares = kumi::map([](auto const& e) { return e*e; }, v); + auto r = kumi::sum( kumi::extract(squares,kumi::index<1>), get<0>(squares)); + return if_else(anyinf, eve::inf(as(r)), r); + } template - KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept { return KYOSU_CALL(v); } + KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept + { return eve::sqr(v); } KYOSU_CALLABLE_OBJECT(sqr_abs_t, sqr_abs_); }; @@ -62,19 +69,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto sqr_abs_(KYOSU_DELAY(), O const&, Z const& v) noexcept - { - if constexpr(concepts::cayley_dickson) - { - auto anyinf = kumi::any_of(v, eve::is_infinite); - auto squares = kumi::map([](auto const& e) { return e*e; }, v); - auto r = kumi::sum( kumi::extract(squares,kumi::index<1>), get<0>(squares)); - return if_else(anyinf, eve::inf(as(r)), r); - } - else return eve::sqr(v); - } -} diff --git a/include/kyosu/functions/sqrt.hpp b/include/kyosu/functions/sqrt.hpp index 2be136c3..3756c8b4 100644 --- a/include/kyosu/functions/sqrt.hpp +++ b/include/kyosu/functions/sqrt.hpp @@ -21,7 +21,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(sqrt_t, sqrt_); }; diff --git a/include/kyosu/functions/tan.hpp b/include/kyosu/functions/tan.hpp index f09b2bd4..37199536 100644 --- a/include/kyosu/functions/tan.hpp +++ b/include/kyosu/functions/tan.hpp @@ -8,6 +8,8 @@ #pragma once #include "eve/traits/as_logical.hpp" #include +#include +#include #include namespace kyosu @@ -17,7 +19,12 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + return mulmi(kyosu::tanh(muli(z))); + else + return kyosu::_::cayley_extend(*this, z); + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -71,20 +78,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto tan_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto t = kyosu::tanh(Z(-kyosu::imag(z), kyosu::real(z))); - return Z(kyosu::imag(t), -kyosu::real(t)); - } - else - { - return cayley_extend(tan, z); - } - } -} diff --git a/include/kyosu/functions/tanh.hpp b/include/kyosu/functions/tanh.hpp index 528687e0..a6d25cbf 100644 --- a/include/kyosu/functions/tanh.hpp +++ b/include/kyosu/functions/tanh.hpp @@ -16,7 +16,23 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto zz = z+z; + auto [rz, iz] = zz; + auto [s, c] = eve::sincos(iz); + auto [sh, ch] = eve::sinhcosh(rz); + auto tmp = c+ch; + auto rr = eve::if_else(eve::is_eqz(kyosu::real(z)), eve::zero, sh/tmp); + auto ii = eve::if_else(kyosu::is_real(z), eve::zero, s/tmp); + return kyosu::if_else(eve::is_infinite(rz), Z(eve::sign(rz)), Z(rr, ii)); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -83,26 +99,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto tanh_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto zz = z+z; - auto [rz, iz] = zz; - auto [s, c] = eve::sincos(iz); - auto [sh, ch] = eve::sinhcosh(rz); - auto tmp = c+ch; - auto rr = eve::if_else(eve::is_eqz(kyosu::real(z)), eve::zero, sh/tmp); - auto ii = eve::if_else(kyosu::is_real(z), eve::zero, s/tmp); - return kyosu::if_else(eve::is_infinite(rz), Z(eve::sign(rz)), Z(rr, ii)); - } - else - { - return cayley_extend(tanh, z); - } - } -} diff --git a/include/kyosu/functions/tanpi.hpp b/include/kyosu/functions/tanpi.hpp index 6b75d0f8..6dbd9246 100644 --- a/include/kyosu/functions/tanpi.hpp +++ b/include/kyosu/functions/tanpi.hpp @@ -8,7 +8,7 @@ #pragma once #include "eve/traits/as_logical.hpp" #include -#include +#include namespace kyosu { @@ -17,7 +17,26 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto machin = [](auto z){ + auto [rz, iz] = z+z; + auto [s, c] = eve::sinpicospi(iz); + auto [sh, ch] = eve::sinhcosh(eve::pi(eve::as(rz))*rz); + auto tmp = c+ch; + auto rr = eve::if_else(kyosu::is_imag(z), eve::zero, sh/tmp); + auto ii = eve::if_else(kyosu::is_real(z),eve:: zero, s/tmp); + return kyosu::if_else(eve::is_infinite(rz), kyosu::complex(sign(rz)), kyosu::complex(rr, ii)); + }; + auto r = machin(kyosu::complex(-kyosu::imag(z), kyosu::real(z))); + return mulmi(r); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,29 +84,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto tanpi_(KYOSU_DELAY(), O const&, Z z) noexcept - { - if constexpr(concepts::complex ) - { - auto machin = [](auto z){ - auto [rz, iz] = z+z; - auto [s, c] = eve::sinpicospi(iz); - auto [sh, ch] = eve::sinhcosh(eve::pi(eve::as(rz))*rz); - auto tmp = c+ch; - auto rr = eve::if_else(kyosu::is_imag(z), eve::zero, sh/tmp); - auto ii = eve::if_else(kyosu::is_real(z),eve:: zero, s/tmp); - return kyosu::if_else(eve::is_infinite(rz), kyosu::complex(sign(rz)), kyosu::complex(rr, ii)); - }; - auto r = machin(kyosu::complex(-kyosu::imag(z), kyosu::real(z))); - return kyosu::complex(kyosu::imag(r), -kyosu::real(r)); - } - else - { - return cayley_extend(tanpi, z); - } - } -} diff --git a/include/kyosu/functions/to_complex.hpp b/include/kyosu/functions/to_complex.hpp index 2474ce4b..456c4a32 100644 --- a/include/kyosu/functions/to_complex.hpp +++ b/include/kyosu/functions/to_complex.hpp @@ -16,21 +16,21 @@ namespace kyosu struct make_complex_t : eve::callable { template - KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept + KYOSU_FORCEINLINE constexpr Z operator()(Z const& v) const noexcept { - return KYOSU_CALL(z); + return v; } template KYOSU_FORCEINLINE constexpr complex_t operator()(T r) const noexcept { - return KYOSU_CALL(r); + return as_cayley_dickson_n_t<2,T>(r, T{0}); } template KYOSU_FORCEINLINE constexpr as_cayley_dickson_n_t<2,R,I> operator()(R r,I i) const noexcept { - return KYOSU_CALL(r,i); + return as_cayley_dickson_n_t<2,R,I>{r, i}; } KYOSU_CALLABLE_OBJECT(make_complex_t, make_complex_); @@ -77,19 +77,3 @@ inline constexpr auto complex = eve::functor; //! @} //==================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto make_complex_(KYOSU_DELAY(), O const&, R v) noexcept - { - if constexpr(eve::floating_value) return as_cayley_dickson_n_t<2,R>(v, R{0}); - else return v; - } - - template - KYOSU_FORCEINLINE constexpr auto make_complex_(KYOSU_DELAY(), O const&, R r, I i) noexcept - { - return as_cayley_dickson_n_t<2,R,I>{r, i}; - } -} diff --git a/include/kyosu/functions/to_polar.hpp b/include/kyosu/functions/to_polar.hpp index 1d8c7c99..37b10ef4 100644 --- a/include/kyosu/functions/to_polar.hpp +++ b/include/kyosu/functions/to_polar.hpp @@ -22,7 +22,7 @@ namespace kyosu template KYOSU_FORCEINLINE constexpr kumi::tuple operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(to_polar_t, to_polar_); }; diff --git a/include/kyosu/functions/trunc.hpp b/include/kyosu/functions/trunc.hpp index adec4c03..23bdddc2 100644 --- a/include/kyosu/functions/trunc.hpp +++ b/include/kyosu/functions/trunc.hpp @@ -16,7 +16,7 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { return Z{kumi::map([](auto const& e) { return eve::trunc(e); }, z)}; } template KYOSU_FORCEINLINE constexpr V operator()(V v) const noexcept @@ -65,12 +65,3 @@ namespace kyosu //! @} //====================================================================================================================== } - -namespace kyosu::_ -{ - template - KYOSU_FORCEINLINE constexpr auto trunc_(KYOSU_DELAY(), O const&, Z c) noexcept - { - return Z{kumi::map([](auto const& e) { return eve::trunc(e); }, c)}; - } -} diff --git a/include/kyosu/functions/zeta.hpp b/include/kyosu/functions/zeta.hpp index 28fd8664..757e88b6 100644 --- a/include/kyosu/functions/zeta.hpp +++ b/include/kyosu/functions/zeta.hpp @@ -19,11 +19,23 @@ namespace kyosu { template KYOSU_FORCEINLINE constexpr Z operator()(Z const& z) const noexcept - { return KYOSU_CALL(z); } + { + if constexpr(concepts::complex ) + { + auto zz=exp2(z); + auto k = zz/(zz-2); + auto g = if_else(z == Z(1), complex(eve::nan(eve::as(real(z)))), k*eta(z)); + return if_else(real(z) == eve::inf(eve::as(real(z))), complex(eve::one(eve::as(real(z)))), g); + } + else + { + return kyosu::_::cayley_extend(*this, z); + } + } template KYOSU_FORCEINLINE constexpr complex_t operator()(V v) const noexcept - { return KYOSU_CALL(complex(v)); } + { return (*this)(complex(v)); } KYOSU_CALLABLE_OBJECT(zeta_t, zeta_); }; diff --git a/test/unit/function/acot.cpp b/test/unit/function/acot.cpp index 05c5f928..1f0c4fbe 100644 --- a/test/unit/function/acot.cpp +++ b/test/unit/function/acot.cpp @@ -28,5 +28,5 @@ TTS_CASE_WITH ( "Check kyosu::acot over quaternion" auto lq = kyosu::acot(q); TTS_RELATIVE_EQUAL(kyosu::cot(lr), r, tts::prec()); TTS_RELATIVE_EQUAL(kyosu::cot(lc), c, tts::prec()); - TTS_RELATIVE_EQUAL(kyosu::cot(lq), q, 2e-2); + TTS_RELATIVE_EQUAL(kyosu::cot(lq), q, tts::prec()); }; diff --git a/test/unit/function/atan.cpp b/test/unit/function/atan.cpp index 1f126753..40a470d6 100644 --- a/test/unit/function/atan.cpp +++ b/test/unit/function/atan.cpp @@ -26,7 +26,7 @@ TTS_CASE_WITH ( "Check kyosu::atan over quaternion" auto lr = kyosu::atan(r); auto lc = kyosu::atan(c); auto lq = kyosu::atan(q); - TTS_RELATIVE_EQUAL(kyosu::tan(lr), kyosu::complex(r), tts::prec()); + TTS_RELATIVE_EQUAL(kyosu::tan(lr), r, tts::prec()); TTS_RELATIVE_EQUAL(kyosu::tan(lc), c, tts::prec()); TTS_RELATIVE_EQUAL(kyosu::tan(lq), q, tts::prec()); }; diff --git a/test/unit/function/atanh.cpp b/test/unit/function/atanh.cpp index af527ebd..065512a3 100644 --- a/test/unit/function/atanh.cpp +++ b/test/unit/function/atanh.cpp @@ -28,5 +28,5 @@ TTS_CASE_WITH ( "Check kyosu::atanh over quaternion" auto lq = kyosu::atanh(q); TTS_RELATIVE_EQUAL(kyosu::tanh(lr), kyosu::complex(r), tts::prec()); TTS_RELATIVE_EQUAL(kyosu::tanh(lc), c, tts::prec()); - TTS_RELATIVE_EQUAL(kyosu::tanh(lq), q, 2e-2); + TTS_RELATIVE_EQUAL(kyosu::tanh(lq), q, tts::prec()); }; diff --git a/test/unit/quaternion/slerp.cpp b/test/unit/quaternion/slerp.cpp deleted file mode 100644 index e1f349be..00000000 --- a/test/unit/quaternion/slerp.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include - - -TTS_CASE_WITH ( "Check behavior of slerp on" - , kyosu::real_types - , tts::generate( tts::randoms(0.25, +0.75) - , tts::randoms(0.25, +0.75) - , tts::randoms(0.25, +0.75) - , tts::randoms(0.25, +0.75) - , tts::randoms(0.25, +0.75) - , tts::randoms(0.25, +0.75) - , tts::randoms(0.25, +0.75) - , tts::randoms(0.25, +0.75) - ) - ) - (T const& a0, T const& a1, T const& a2, T const& a3 - , T const& a4, T const& a5, T const& a6, T const& a7) -{ - using e_t = eve::element_type_t; - using q_t = kyosu::quaternion_t; - if constexpr(sizeof(e_t) == 8) - { - auto z1 = kyosu::sign(q_t(a0, a1, a2, a3)); - auto z2 = kyosu::sign(q_t(a4, a5, a6, a7)); - auto dz1z2 = kyosu::real(kyosu::dot(z1, z2)); - z2 = kyosu::if_else(eve::is_gez(dz1z2), z2, -z2); - auto r1 = kyosu::slerp(z1, z2, e_t(0.0)); - auto t1 = kyosu::conj(z1)*z2; - auto t2 = kyosu::pow(t1, e_t(0.0)); - auto t3 = z1*t2; - TTS_RELATIVE_EQUAL(r1, t3, 0.0001); - } -};