From 65412d33d9bec22ee5f9eaa06e4b9d46de302950 Mon Sep 17 00:00:00 2001 From: jtlap Date: Sun, 24 Sep 2023 17:05:57 +0200 Subject: [PATCH] More documentation tests --- include/kyosu/complex/lrising_factorial.hpp | 2 +- include/kyosu/complex/polar.hpp | 78 -------------- include/kyosu/complex/rising_factorial.hpp | 2 +- include/kyosu/functions.hpp | 3 +- include/kyosu/functions/convert.hpp | 9 +- include/kyosu/functions/from_angle_axis.hpp | 21 ++-- include/kyosu/functions/from_cylindrical.hpp | 2 +- .../functions/from_cylindricospherical.hpp | 14 +-- ...tipolar.hpp => from_cylindrospherical.hpp} | 45 ++++---- include/kyosu/functions/from_euler.hpp | 2 +- include/kyosu/functions/from_multipolar.hpp | 2 +- include/kyosu/functions/from_polar.hpp | 2 +- .../kyosu/functions/from_rotation_matrix.hpp | 21 ++-- include/kyosu/functions/from_semipolar.hpp | 2 +- include/kyosu/functions/from_spherical.hpp | 2 +- include/kyosu/functions/if_else.hpp | 6 +- include/kyosu/functions/purepart.hpp | 77 -------------- include/kyosu/functions/rot_angle.hpp | 4 +- include/kyosu/functions/rot_axis.hpp | 2 +- include/kyosu/functions/rotate_vec.hpp | 17 ++- include/kyosu/functions/semipolar.hpp | 100 ------------------ include/kyosu/functions/to_angle_axis.hpp | 2 +- include/kyosu/functions/to_cylindrical.hpp | 2 +- include/kyosu/functions/to_multipolar.hpp | 2 +- include/kyosu/functions/to_polar.hpp | 2 +- .../kyosu/functions/to_rotation_matrix.hpp | 2 +- include/kyosu/functions/to_semipolar.hpp | 2 +- include/kyosu/functions/to_spherical.hpp | 2 +- include/kyosu/types/impl/arithmetic.hpp | 5 +- include/kyosu/types/impl/math.hpp | 2 +- .../kyosu/types/impl/quaternion/specific.hpp | 11 +- include/kyosu/types/impl/trigo.hpp | 88 +++++++++++++++ include/kyosu/types/impl/trigo_pi.hpp | 16 +-- test/doc/conversions.cpp | 32 ------ test/doc/dot.cpp | 1 + test/doc/exp_i.cpp | 25 +++++ test/doc/exp_ipi.cpp | 25 +++++ test/doc/from_angle_axis.cpp | 25 +++++ test/doc/from_cylindrospherical.cpp | 21 ++++ test/doc/from_multipolar.cpp | 22 ++++ test/doc/from_polar.cpp | 21 ++++ test/doc/from_rotation_matrix.cpp | 32 ++++++ test/doc/from_semipolar.cpp | 22 ++++ test/doc/from_spherical.cpp | 22 ++++ test/doc/ldiv.cpp | 51 +++++++++ test/doc/lerp.cpp | 52 +++++++++ test/doc/lrising_factorial.cpp | 34 ++++++ test/doc/pow.cpp | 51 +++++++++ test/doc/pow1p.cpp | 51 +++++++++ test/doc/pow_abs.cpp | 51 +++++++++ test/doc/powm1.cpp | 51 +++++++++ test/doc/radinpi.cpp | 25 +++++ test/doc/rec.cpp | 25 +++++ test/doc/rising_factorial.cpp | 33 ++++++ test/doc/rot_angle.cpp | 25 +++++ test/doc/rot_axis.cpp | 24 +++++ test/doc/rotate_vec.cpp | 19 ++++ test/doc/sec.cpp | 25 +++++ test/doc/sech.cpp | 25 +++++ test/doc/secpi.cpp | 25 +++++ test/doc/sign.cpp | 25 +++++ test/doc/sin.cpp | 25 +++++ test/doc/sinc.cpp | 25 +++++ test/doc/sincos.cpp | 25 +++++ test/doc/sinh.cpp | 25 +++++ test/doc/sinhcosh.cpp | 25 +++++ test/doc/sinpi.cpp | 25 +++++ test/doc/sinpicospi.cpp | 25 +++++ test/doc/slerp.cpp | 58 ++++++++++ test/doc/sqr_abs.cpp | 25 +++++ test/doc/sqrt.cpp | 25 +++++ test/doc/tan.cpp | 25 +++++ test/doc/tanh.cpp | 25 +++++ test/doc/tanpi.cpp | 25 +++++ test/doc/to_angle_axis.cpp | 31 ++++++ test/doc/to_cylindrical.cpp | 36 +++++++ test/doc/to_euler.cpp | 51 +++++++++ test/doc/to_multipolar.cpp | 51 +++++++++ test/doc/to_polar.cpp | 32 ++++++ test/doc/to_rotation_matrix | 36 +++++++ test/doc/to_rotation_matrix.cpp | 28 +++++ test/doc/to_semipolar.cpp | 36 +++++++ test/doc/to_spherical.cpp | 36 +++++++ 83 files changed, 1694 insertions(+), 390 deletions(-) delete mode 100644 include/kyosu/complex/polar.hpp rename include/kyosu/functions/{multipolar.hpp => from_cylindrospherical.hpp} (54%) delete mode 100644 include/kyosu/functions/purepart.hpp delete mode 100644 include/kyosu/functions/semipolar.hpp delete mode 100644 test/doc/conversions.cpp create mode 100644 test/doc/exp_i.cpp create mode 100644 test/doc/exp_ipi.cpp create mode 100644 test/doc/from_angle_axis.cpp create mode 100644 test/doc/from_cylindrospherical.cpp create mode 100644 test/doc/from_multipolar.cpp create mode 100644 test/doc/from_polar.cpp create mode 100644 test/doc/from_rotation_matrix.cpp create mode 100644 test/doc/from_semipolar.cpp create mode 100644 test/doc/from_spherical.cpp create mode 100644 test/doc/ldiv.cpp create mode 100644 test/doc/lerp.cpp create mode 100644 test/doc/lrising_factorial.cpp create mode 100644 test/doc/pow.cpp create mode 100644 test/doc/pow1p.cpp create mode 100644 test/doc/pow_abs.cpp create mode 100644 test/doc/powm1.cpp create mode 100644 test/doc/radinpi.cpp create mode 100644 test/doc/rec.cpp create mode 100644 test/doc/rising_factorial.cpp create mode 100644 test/doc/rot_angle.cpp create mode 100644 test/doc/rot_axis.cpp create mode 100644 test/doc/rotate_vec.cpp create mode 100644 test/doc/sec.cpp create mode 100644 test/doc/sech.cpp create mode 100644 test/doc/secpi.cpp create mode 100644 test/doc/sign.cpp create mode 100644 test/doc/sin.cpp create mode 100644 test/doc/sinc.cpp create mode 100644 test/doc/sincos.cpp create mode 100644 test/doc/sinh.cpp create mode 100644 test/doc/sinhcosh.cpp create mode 100644 test/doc/sinpi.cpp create mode 100644 test/doc/sinpicospi.cpp create mode 100644 test/doc/slerp.cpp create mode 100644 test/doc/sqr_abs.cpp create mode 100644 test/doc/sqrt.cpp create mode 100644 test/doc/tan.cpp create mode 100644 test/doc/tanh.cpp create mode 100644 test/doc/tanpi.cpp create mode 100644 test/doc/to_angle_axis.cpp create mode 100644 test/doc/to_cylindrical.cpp create mode 100644 test/doc/to_euler.cpp create mode 100644 test/doc/to_multipolar.cpp create mode 100644 test/doc/to_polar.cpp create mode 100644 test/doc/to_rotation_matrix create mode 100644 test/doc/to_rotation_matrix.cpp create mode 100644 test/doc/to_semipolar.cpp create mode 100644 test/doc/to_spherical.cpp diff --git a/include/kyosu/complex/lrising_factorial.hpp b/include/kyosu/complex/lrising_factorial.hpp index de1c9661..5d1f19f7 100644 --- a/include/kyosu/complex/lrising_factorial.hpp +++ b/include/kyosu/complex/lrising_factorial.hpp @@ -20,7 +20,7 @@ namespace kyosu::tags template static KYOSU_FORCEINLINE auto deferred_call(auto, T1 const& v, T2 const& w) noexcept { auto fn = callable_lrising_factorial{}; - return fn(v, w); } + return fn(complex(v), complex(w)); } template KYOSU_FORCEINLINE auto operator()(T1 const& target1, T2 const& target2) const noexcept -> decltype(eve::tag_invoke(*this, target1, target2)) diff --git a/include/kyosu/complex/polar.hpp b/include/kyosu/complex/polar.hpp deleted file mode 100644 index bac79926..00000000 --- a/include/kyosu/complex/polar.hpp +++ /dev/null @@ -1,78 +0,0 @@ -//====================================================================================================================== -/* - Kyosu - Complex Without Complexes - Copyright : KYOSU Contributors & Maintainers - SPDX-License-Identifier: BSL-1.0 -*/ -//====================================================================================================================== -#pragma once - -#include - -namespace kyosu::tags -{ - struct callable_polar : eve::elementwise - { - using callable_tag_type = callable_polar; - - KYOSU_DEFERS_CALLABLE(polar_); - - template - static KYOSU_FORCEINLINE auto deferred_call(auto, T0 const& rho, T1 const & theta) noexcept - { - auto [s, c] = eve::sincos(theta); - return kyosu::complex(rho*c, eve::if_else(eve::is_eqz(s), eve::zero, rho*s)); - } - - template - KYOSU_FORCEINLINE auto operator()(T0 const& target0, T1 const& target1) const noexcept - -> decltype(eve::tag_invoke(*this, target0, target1)) - { - return eve::tag_invoke(*this, target0, target1); - } - - template - eve::unsupported_call operator()(T&&... x) const - requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; - }; -} - -namespace kyosu -{ -//====================================================================================================================== -//! @addtogroup functions -//! @{ -//! @var polar -//! @brief complex number from modulus and argument. -//! -//! **Defined in Header** -//! -//! @code -//! #include -//! @endcode -//! -//! @groupheader{Callable Signatures} -//! -//! @code -//! namespace kyosu -//! { -//! template constexpr auto polar(T0 rho, T1 theta) noexcept; -//! } -//! @endcode -//! -//! **Parameters** -//! -//! * `rho` : modulus. -//! * `theta` : argument. -//! -//! **Return value** -//! -//! Returns elementwise true the polarument of the complex number i.e. \f$\rho e^{i\theta}\f$. -//! -//! @groupheader{Example} -//! -//! @godbolt{doc/polar.cpp} -//! @} -//====================================================================================================================== -inline constexpr tags::callable_polar polar = {}; -} diff --git a/include/kyosu/complex/rising_factorial.hpp b/include/kyosu/complex/rising_factorial.hpp index add8c8ec..d3b9d044 100644 --- a/include/kyosu/complex/rising_factorial.hpp +++ b/include/kyosu/complex/rising_factorial.hpp @@ -20,7 +20,7 @@ namespace kyosu::tags template static KYOSU_FORCEINLINE auto deferred_call(auto, T1 const& v, T2 const& w) noexcept { auto fn = callable_rising_factorial{}; - return fn(v, w); } + return fn(complex(v), complex(w)); } template KYOSU_FORCEINLINE auto operator()(T1 const& target1, T2 const& target2) const noexcept -> decltype(eve::tag_invoke(*this, target1, target2)) diff --git a/include/kyosu/functions.hpp b/include/kyosu/functions.hpp index 9fc6b0e3..8d54da1e 100644 --- a/include/kyosu/functions.hpp +++ b/include/kyosu/functions.hpp @@ -139,7 +139,6 @@ #include #include #include -#include #include #include #include @@ -152,8 +151,10 @@ #include #include +#include #include #include +#include #include #include #include diff --git a/include/kyosu/functions/convert.hpp b/include/kyosu/functions/convert.hpp index a36c9378..2fc80022 100644 --- a/include/kyosu/functions/convert.hpp +++ b/include/kyosu/functions/convert.hpp @@ -42,7 +42,7 @@ namespace kyosu //! @addtogroup functions //! @{ //! @var convert -//! @brief Select a value between two arguments based on a logical mask +//! @brief convert to a target typek //! //! **Defined in Header** //! @@ -55,14 +55,15 @@ namespace kyosu //! @code //! namespace kyosu //! { -//! template -//! constexpr auto convert(T x, U, y, V z ) noexcept; +//! template +//! constexpr auto convert(T x, eve::as ) noexcept; //! } //! @endcode //! //! **Parameters** //! -//! * `z` : Value to process. +//! * `x` : Value to process. +//! * `U``: target scalar type to convert to. //! //! **Return value** //! diff --git a/include/kyosu/functions/from_angle_axis.hpp b/include/kyosu/functions/from_angle_axis.hpp index 4d9c2c71..368bb229 100644 --- a/include/kyosu/functions/from_angle_axis.hpp +++ b/include/kyosu/functions/from_angle_axis.hpp @@ -19,28 +19,29 @@ namespace kyosu::tags KYOSU_DEFERS_CALLABLE(from_angle_axis_); - template + template static KYOSU_FORCEINLINE auto deferred_call(auto - , V const & angle - , std::span axis) noexcept + , V angle + , U axis) noexcept { - auto q = quaternion(U(0), axis[0], axis[1], axis[2]); + using e_t = decltype(axis[0]+angle); + auto q = quaternion(e_t(0), e_t(axis[0]), e_t(axis[1]), e_t(axis[2])); auto [s, c] = eve::sincos(angle*eve::half(eve::as(angle))); return c+s*q; } template - KYOSU_FORCEINLINE auto operator()(T0 const& target0, - T1 const& target1 + KYOSU_FORCEINLINE auto operator()(T0 target0, + T1 target1 ) const noexcept -> decltype(eve::tag_invoke(*this, target0, target1)) { return eve::tag_invoke(*this, target0, target1); } - template - eve::unsupported_call operator()(T&&... x) const - requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; +// template +// eve::unsupported_call operator()(T&&... x) const +// requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; }; } @@ -83,7 +84,7 @@ namespace kyosu //! //! @groupheader{Example} //! - //! @godbolt{doc/quaternion/regular/conversions.cpp} + //! @godbolt{doc/from_angle_axis.cpp} //! @} //================================================================================================ inline constexpr tags::callable_from_angle_axis from_angle_axis = {}; diff --git a/include/kyosu/functions/from_cylindrical.hpp b/include/kyosu/functions/from_cylindrical.hpp index 9958e5d1..1e03a822 100644 --- a/include/kyosu/functions/from_cylindrical.hpp +++ b/include/kyosu/functions/from_cylindrical.hpp @@ -89,7 +89,7 @@ namespace kyosu //! //! @groupheader{Example} //! - //! @godbolt{doc/quaternion/regular/conversions.cpp} + //! @godbolt{doc/from_cylindrical.cpp} //! @} //================================================================================================ inline constexpr tags::callable_from_cylindrical from_cylindrical = {}; diff --git a/include/kyosu/functions/from_cylindricospherical.hpp b/include/kyosu/functions/from_cylindricospherical.hpp index 6c2cfd29..900ed386 100644 --- a/include/kyosu/functions/from_cylindricospherical.hpp +++ b/include/kyosu/functions/from_cylindricospherical.hpp @@ -20,15 +20,15 @@ namespace kyosu::tags template static KYOSU_FORCEINLINE auto deferred_call(auto - , V const & r - , U const & angle - , W const & h1 - , T const & h2) noexcept + , V const & t + , U const & radius + , W const & longitude + , T const & latitude) noexcept { auto [slat, clat] = eve::sincos(latitude); auto [slon, clon] = eve::sincos(longitude); - auto f = r*clat; - return kyosu::quaternion(t, f*clon, f*slon, r*slat); + auto f = radius*clat; + return kyosu::quaternion(t, f*clon, f*slon, radius*slat); } template @@ -91,7 +91,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/conversions.cpp} + //! @godbolt{doc/from_cylindrospherical.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/multipolar.hpp b/include/kyosu/functions/from_cylindrospherical.hpp similarity index 54% rename from include/kyosu/functions/multipolar.hpp rename to include/kyosu/functions/from_cylindrospherical.hpp index 3a2495e4..900ed386 100644 --- a/include/kyosu/functions/multipolar.hpp +++ b/include/kyosu/functions/from_cylindrospherical.hpp @@ -12,23 +12,23 @@ namespace kyosu::tags { - struct callable_from_multipolar : eve::elementwise + struct callable_from_cylindrospherical : eve::elementwise { - using callable_tag_type = callable_from_multipolar; + using callable_tag_type = callable_from_cylindrospherical; - KYOSU_DEFERS_CALLABLE(from_multipolar_); + KYOSU_DEFERS_CALLABLE(from_cylindrospherical_); template static KYOSU_FORCEINLINE auto deferred_call(auto - , V const & rho1 - , U const & theta1 - , W const & rho2 - , T const & theta2) noexcept + , V const & t + , U const & radius + , W const & longitude + , T const & latitude) noexcept { auto [slat, clat] = eve::sincos(latitude); auto [slon, clon] = eve::sincos(longitude); - auto f = r*clat; - return kyosu::quaternion(t, f*clon, f*slon, r*slat); + auto f = radius*clat; + return kyosu::quaternion(t, f*clon, f*slon, radius*slat); } template @@ -43,24 +43,25 @@ namespace kyosu::tags } template - eve::unsupported_call operator()(T&&... x) const + eve::unsupported_call operator()(T&&... x) const requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; }; } namespace kyosu { - //================================================================================================ + //================================================================================================ //! @addtogroup quaternion //! @{ - //! @var from_multipolar - //! - //! @brief Callable object computing a quaternion from its multipolar representation. + //! @var from_cylindrospherical //! - //! This function build quaternions in a way similar to the way polar builds complex numbers - //! from a multipolar representation of an \f$\mathbb{R}^4\f$ element. + //! @brief Callable object computing a quaternion from its cylindrospherical representation. //! - //! from_multipolar the two \f$\mathbb{C}\f$ components of the quaternion are given in polar coordinates + //! cylindrospherical is specific to quaternions. It is often interesting to consider + //! \f$\mathbb{H}\f$ as the cartesian product of \f$\mathbb{R}\f$ by \f$\mathbb{R3}\f$ + //! (the quaternionic multiplication has then a special form, as given here). + //! This function therefore builds a quaternion from this representation, with the \f$\mathbb{R3}\f$ component given + //! in usual \f$\mathbb{R3}\f$ spherical coordinates. //! //! **Defined in header** //! @@ -73,14 +74,14 @@ namespace kyosu //! @code //! namespace eve //! { - //! auto from_multipolar( auto rho1, auto theta1 auto rho2, auto theta2) const noexcept; + //! auto from_cylindrospherical(auto t, auto radius, auto longitude, auto latitude) const noexcept; //! } //! @endcode //! //! **Parameters** //! - //!`rho1`, `rho2`: the moduli - //! 'theta1', 'theta2': the angles in radian + //! * `t`, `radius`: the moduli + //! * `longitude`, `latitude`: angles in radian //! //! **Return value** //! @@ -90,9 +91,9 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/conversions.cpp} + //! @godbolt{doc/from_cylindrospherical.cpp} //! //! @} //================================================================================================ - inline constexpr tags::callable_from_multipolar from_multipolar = {}; + inline constexpr tags::callable_from_cylindrospherical from_cylindrospherical = {}; } diff --git a/include/kyosu/functions/from_euler.hpp b/include/kyosu/functions/from_euler.hpp index 5504acb7..a900afdd 100644 --- a/include/kyosu/functions/from_euler.hpp +++ b/include/kyosu/functions/from_euler.hpp @@ -144,7 +144,7 @@ namespace kyosu //! //! @groupheader{Example} //! - //! @godbolt{doc/quaternion/regular/from_euler.cpp} + //! @godbolt{doc/from_euler.cpp} //! @} //================================================================================================ inline constexpr tags::callable_from_euler from_euler = {}; diff --git a/include/kyosu/functions/from_multipolar.hpp b/include/kyosu/functions/from_multipolar.hpp index 55f1a6cb..983df8be 100644 --- a/include/kyosu/functions/from_multipolar.hpp +++ b/include/kyosu/functions/from_multipolar.hpp @@ -90,7 +90,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/conversions.cpp} + //! @godbolt{doc/from_multipolar.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/from_polar.hpp b/include/kyosu/functions/from_polar.hpp index 1d4ea786..c44f6948 100644 --- a/include/kyosu/functions/from_polar.hpp +++ b/include/kyosu/functions/from_polar.hpp @@ -84,7 +84,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/from_polar.cpp} + //! @godbolt{doc/from_polar.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/from_rotation_matrix.hpp b/include/kyosu/functions/from_rotation_matrix.hpp index a3390298..f1653e60 100644 --- a/include/kyosu/functions/from_rotation_matrix.hpp +++ b/include/kyosu/functions/from_rotation_matrix.hpp @@ -36,24 +36,21 @@ namespace kyosu::tags auto r20pr02 = r[2][0] + r[0][2]; auto r12pr21 = r[1][2] + r[2][1]; - auto h = half(as(r11pr22)); - auto q0 = eve::sqrt(eve::if_else(is_gtz(qq0m1), eve::inc(qq0m1), (eve::sqr(r21mr12)+sqr(r02mr20)+eve::sqr(r10mr01))/(3-qq0m1)))*h; - auto q1 = eve::sqrt(eve::if_else(is_gtz(qq1m1), eve::inc(qq1m1), (eve::sqr(r21mr12)+sqr(r01pr10)+eve::sqr(r20pr02))/(3-qq1m1)))*h; - auto q2 = eve::sqrt(eve::if_else(is_gtz(qq2m1), eve::inc(qq2m1), (eve::sqr(r02mr20)+sqr(r01pr10)+eve::sqr(r12pr21))/(3-qq2m1)))*h; - auto q3 = eve::sqrt(eve::if_else(is_gtz(qq3m1), eve::inc(qq3m1), (eve::sqr(r10mr01)+sqr(r20pr02)+eve::sqr(r12pr21))/(3-qq3m1)))*h; + auto h = eve::half(eve::as(r11pr22)); + auto q0 = eve::sqrt(eve::if_else(eve::is_gtz(qq0m1), eve::inc(qq0m1), (eve::sqr(r21mr12)+sqr(r02mr20)+eve::sqr(r10mr01))/(3-qq0m1)))*h; + auto q1 = eve::sqrt(eve::if_else(eve::is_gtz(qq1m1), eve::inc(qq1m1), (eve::sqr(r21mr12)+sqr(r01pr10)+eve::sqr(r20pr02))/(3-qq1m1)))*h; + auto q2 = eve::sqrt(eve::if_else(eve::is_gtz(qq2m1), eve::inc(qq2m1), (eve::sqr(r02mr20)+sqr(r01pr10)+eve::sqr(r12pr21))/(3-qq2m1)))*h; + auto q3 = eve::sqrt(eve::if_else(eve::is_gtz(qq3m1), eve::inc(qq3m1), (eve::sqr(r10mr01)+sqr(r20pr02)+eve::sqr(r12pr21))/(3-qq3m1)))*h; using e_t = decltype(r11pr22); return quaternion(q0, q1, q2, q3); } - template - KYOSU_FORCEINLINE auto operator()(T0 const& target0, - T1 const& target1, - T2 const& target2, - T3 const& target3 + template + KYOSU_FORCEINLINE auto operator()(T0 const& target0 ) const noexcept - -> decltype(eve::tag_invoke(*this, target0, target1, target2, target3)) + -> decltype(eve::tag_invoke(*this, target0)) { - return eve::tag_invoke(*this, target0, target1, target2, target3); + return eve::tag_invoke(*this, target0); } template diff --git a/include/kyosu/functions/from_semipolar.hpp b/include/kyosu/functions/from_semipolar.hpp index d9bc39c8..e061c11e 100644 --- a/include/kyosu/functions/from_semipolar.hpp +++ b/include/kyosu/functions/from_semipolar.hpp @@ -90,7 +90,7 @@ namespace kyosu //! //! @groupheader{Example} //! - //! @godbolt{doc/quaternion/regular/conversions.cpp} + //! @godbolt{doc/from_semipolar.cpp} //! @} //================================================================================================ inline constexpr tags::callable_from_semipolar from_semipolar = {}; diff --git a/include/kyosu/functions/from_spherical.hpp b/include/kyosu/functions/from_spherical.hpp index 787990e1..9f0dae5b 100644 --- a/include/kyosu/functions/from_spherical.hpp +++ b/include/kyosu/functions/from_spherical.hpp @@ -93,7 +93,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/conversions.cpp} + //! @godbolt{doc/from_spherical.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/if_else.hpp b/include/kyosu/functions/if_else.hpp index 79de3865..eba57444 100644 --- a/include/kyosu/functions/if_else.hpp +++ b/include/kyosu/functions/if_else.hpp @@ -21,9 +21,9 @@ namespace kyosu::tags return eve::tag_invoke(*this, m, t, f); } - template - eve::unsupported_call operator()(T&&... x) const - requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; +// template +// eve::unsupported_call operator()(T&&... x) const +// requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; }; } diff --git a/include/kyosu/functions/purepart.hpp b/include/kyosu/functions/purepart.hpp deleted file mode 100644 index 5f9dd5c6..00000000 --- a/include/kyosu/functions/purepart.hpp +++ /dev/null @@ -1,77 +0,0 @@ -//====================================================================================================================== -/* - Kyosu - Complex Without Complexes - Copyright : KYOSU Contributors & Maintainers - SPDX-License-Identifier: BSL-1.0 -*/ -//====================================================================================================================== -#pragma once - -#include - -namespace kyosu::tags -{ - struct callable_purepart : eve::elementwise, extractor<1,-1> - { - using callable_tag_type = callable_purepart; - - KYOSU_DEFERS_CALLABLE(purepart_); - - template - static KYOSU_FORCEINLINE auto deferred_call(auto, T const&) noexcept { return T{0}; } - - template - KYOSU_FORCEINLINE auto operator()(T const& target) const noexcept -> decltype(eve::tag_invoke(*this, target)) - { - return eve::tag_invoke(*this, target); - } - - template - eve::unsupported_call operator()(T&&... x) const - requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; - }; -} - -namespace kyosu -{ -//====================================================================================================================== -//! @addtogroup functions -//! @{ -//! @var purepart -//! @brief Extracts the pure part of a value. -//! -//! **Defined in Header** -//! -//! @code -//! #include -//! @endcode -//! -//! @groupheader{Callable Signatures} -//! -//! @code -//! namespace kyosu -//! { -//! template constexpr auto purepart(T const& z) noexcept; -//! template constexpr T purepart(T const& z) noexcept; -//! } -//! @endcode -//! -//! **Parameters** -//! -//! * `z` : Original value. -//! -//! **Return value** -//! -//! Returns the pure part of its argument, ie the tuple of all its non-real components. -//! For real inputs, the call returns 0. -//! -//! @groupheader{Example} -//! -//! @godbolt{doc/purepart.cpp} -//====================================================================================================================== -inline constexpr tags::callable_purepart purepart = {}; - -//====================================================================================================================== -//! @} -//====================================================================================================================== -} diff --git a/include/kyosu/functions/rot_angle.hpp b/include/kyosu/functions/rot_angle.hpp index 23ccef2b..2918995f 100644 --- a/include/kyosu/functions/rot_angle.hpp +++ b/include/kyosu/functions/rot_angle.hpp @@ -21,7 +21,7 @@ namespace kyosu::tags static KYOSU_FORCEINLINE auto deferred_call(auto , V const & v) noexcept { - return eve::zero(as(v)); + return eve::zero(eve::as(v)); } template @@ -76,7 +76,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/rot_angle.cpp} + //! @godbolt{doc/rot_angle.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/rot_axis.hpp b/include/kyosu/functions/rot_axis.hpp index e6913e34..42f6ff0d 100644 --- a/include/kyosu/functions/rot_axis.hpp +++ b/include/kyosu/functions/rot_axis.hpp @@ -77,7 +77,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/rot_axis.cpp} + //! @godbolt{doc/rot_axis.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/rotate_vec.hpp b/include/kyosu/functions/rotate_vec.hpp index 6febedc6..3ac1ffd6 100644 --- a/include/kyosu/functions/rotate_vec.hpp +++ b/include/kyosu/functions/rotate_vec.hpp @@ -19,20 +19,19 @@ namespace kyosu::tags KYOSU_DEFERS_CALLABLE(rotate_vec_); - template + template static KYOSU_FORCEINLINE auto deferred_call(auto , V const & - , std::span const & v + , U const & v , _::norming) noexcept { return v; } - template + template static KYOSU_FORCEINLINE auto deferred_call(auto , V const & - , std::span const & v + , U const & v ) noexcept { return v; @@ -50,9 +49,9 @@ namespace kyosu::tags template KYOSU_FORCEINLINE auto operator()(T0 const& target0, T1 const& target1) const noexcept - -> decltype(eve::tag_invoke(*this, target0, target1)) + -> decltype(eve::tag_invoke(*this, target0, target1, _::norming())) { - return eve::tag_invoke(*this, target0, target1, normalize); + return eve::tag_invoke(*this, target0, target1, _::norming{} ); } template @@ -87,7 +86,7 @@ namespace kyosu //! //! **Parameters** //! - //! `q`: [quaternion](@ref eve::value) defining the rotation. + //! `q`: quaternion value defining the rotation. //! `x`: span of 3 elements to rotate //! //! **Return value** @@ -98,7 +97,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/rotate_vec.cpp} + //! @godbolt{doc/rotate_vec.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/semipolar.hpp b/include/kyosu/functions/semipolar.hpp deleted file mode 100644 index 91efee1d..00000000 --- a/include/kyosu/functions/semipolar.hpp +++ /dev/null @@ -1,100 +0,0 @@ -//================================================================================================== -/* - KYOSU - Expressive Vector Engine - Copyright : KYOSU Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include - -namespace kyosu::tags -{ - struct callable_from_semipolar : eve::elementwise - { - using callable_tag_type = callable_from_semipolar; - - KYOSU_DEFERS_CALLABLE(from_semipolar_); - - template - static KYOSU_FORCEINLINE auto deferred_call(auto - , V const & rho - , U const & alpha - , W const & theta1 - , T const & theta2) noexcept - { - using z_t = eve::quaternion_t; - auto [st1, ct1] = eve::sincos(theta1); - auto [st2, ct2] = eve::sincos(theta2); - auto [sa, ca] = eve::sincos(alpha); - return rho*quaternion(ca*ct1, ca*st1, sa*ct2, sa*st2); - } - - template - KYOSU_FORCEINLINE auto operator()(T0 const& target0, - T1 const& target1, - T2 const& target2, - T3 const& target3 - ) const noexcept - -> decltype(eve::tag_invoke(*this, target0, target1, target2, target3)) - { - return eve::tag_invoke(*this, target0, target1, target2, target3); - } - - template - eve::unsupported_call operator()(T&&... x) const - requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; - }; -} - -namespace kyosu -{ - //================================================================================================ - //! @addtogroup quaternion - //! @{ - //! @var from_semipolar - //! - //! @brief Callable object computing a quaternion from its semipolar representation. - //! - //! This function build quaternions in a way similar to the way polar builds complex numbers - //! from a semipolar representation of an \f$\mathbb{R}^4\f$ element. - //! - //! from_semipolar takes as a first input the magnitude of the quaternion, - //! as a second input an angle in the range 0 to \f$\pi/2\f$ such that magnitudes of the first - //! two \f$\mathbb{C}\f$ components of the quaternion are the product of the first input and the sine and cosine - //! of this angle, respectively, and finally as third and fourth inputs angles in the range \f$-\pi/2\f$ to \f$+\pi/2\f$ - //! which represent the arguments of the first and second \f$\mathbb{C}\f$ components of the quaternion, respectively. - //! - //! **Defined in header** - //! - //! @code - //! #include eve/module/quaternion.hpp>` - //! @endcode - //! - //! @groupheader{Callable Signatures} - //! - //! @code - //! namespace eve - //! { - //! auto from_semipolar(auto rho, auto alpha auto theta1, auto theta2) const noexcept; - //! } - //! @endcode - //! - //! **Parameters** - //! - //! * `rho`: the modulus - //! * `alpha`, `theta1`, `theta2`: angles in radian - //! - //! **Return value** - //! - //! the quaternion value representing the \f$\R^4\f$ element. - //! - //! @groupheader{Example} - //! - //! @godbolt{doc/conversions.cpp} - //! @} - //================================================================================================ - inline constexpr tags::callable_from_semipolar from_semipolar = {}; -} diff --git a/include/kyosu/functions/to_angle_axis.hpp b/include/kyosu/functions/to_angle_axis.hpp index b18cbf13..62a11a66 100644 --- a/include/kyosu/functions/to_angle_axis.hpp +++ b/include/kyosu/functions/to_angle_axis.hpp @@ -78,7 +78,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/to_angle_axis.cpp} + //! @godbolt{doc/to_angle_axis.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/to_cylindrical.hpp b/include/kyosu/functions/to_cylindrical.hpp index bb2421ba..61492b65 100644 --- a/include/kyosu/functions/to_cylindrical.hpp +++ b/include/kyosu/functions/to_cylindrical.hpp @@ -79,7 +79,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/to_cylindrical.cpp} + //! @godbolt{doc/to_cylindrical.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/to_multipolar.hpp b/include/kyosu/functions/to_multipolar.hpp index a4465aca..5ead8668 100644 --- a/include/kyosu/functions/to_multipolar.hpp +++ b/include/kyosu/functions/to_multipolar.hpp @@ -79,7 +79,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/to_multipolar.cpp} + //! @godbolt{doc/to_multipolar.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/to_polar.hpp b/include/kyosu/functions/to_polar.hpp index 519e348c..ade8ce12 100644 --- a/include/kyosu/functions/to_polar.hpp +++ b/include/kyosu/functions/to_polar.hpp @@ -79,7 +79,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/to_polar.cpp} + //! @godbolt{doc/to_polar.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/to_rotation_matrix.hpp b/include/kyosu/functions/to_rotation_matrix.hpp index a59aea68..398c96ad 100644 --- a/include/kyosu/functions/to_rotation_matrix.hpp +++ b/include/kyosu/functions/to_rotation_matrix.hpp @@ -109,7 +109,7 @@ namespace kyosu //! //! @groupheader{Example} //! - //! @godbolt{doc/quaternion/regular/to_rotation_matrix.cpp} + //! @godbolt{doc/to_rotation_matrix.cpp} //! @} //================================================================================================ inline constexpr tags::callable_to_rotation_matrix to_rotation_matrix = {}; diff --git a/include/kyosu/functions/to_semipolar.hpp b/include/kyosu/functions/to_semipolar.hpp index d26bdb92..2388f389 100644 --- a/include/kyosu/functions/to_semipolar.hpp +++ b/include/kyosu/functions/to_semipolar.hpp @@ -79,7 +79,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/to_semipolar.cpp} + //! @godbolt{doc/to_semipolar.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/functions/to_spherical.hpp b/include/kyosu/functions/to_spherical.hpp index 52442dc8..46fb0999 100644 --- a/include/kyosu/functions/to_spherical.hpp +++ b/include/kyosu/functions/to_spherical.hpp @@ -79,7 +79,7 @@ namespace kyosu //! //! #### Example //! - //! @godbolt{doc/quaternion/regular/to_spherical.cpp} + //! @godbolt{doc/to_spherical.cpp} //! //! @} //================================================================================================ diff --git a/include/kyosu/types/impl/arithmetic.hpp b/include/kyosu/types/impl/arithmetic.hpp index 7854aab1..f035268a 100644 --- a/include/kyosu/types/impl/arithmetic.hpp +++ b/include/kyosu/types/impl/arithmetic.hpp @@ -133,12 +133,12 @@ namespace kyosu::_ return kyosu::dist(c0, c1)/eve::max(kyosu::abs(c0), kyosu::abs(c1), eve::one(eve::as(abs(c0)))); } - template + template KYOSU_FORCEINLINE constexpr auto dispatch(eve::tag_of const&, C0 const & c0, C1 const & c1, T const & 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); }, c0, c1)}; + 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 @@ -255,7 +255,6 @@ namespace kyosu::_ using real_t = eve::as>; constexpr auto P = kyosu::dimension_v; if constexpr (P == 2) -// std::cout << c << " -> " << is_infinite(c) << std::endl; return if_else(is_infinite(c) , complex(eve::inf(real_t{}), eve::copysign(eve::zero(real_t{}), imag(c))) , c); diff --git a/include/kyosu/types/impl/math.hpp b/include/kyosu/types/impl/math.hpp index 5008582d..6a6751e1 100644 --- a/include/kyosu/types/impl/math.hpp +++ b/include/kyosu/types/impl/math.hpp @@ -388,7 +388,7 @@ namespace kyosu::_ auto lgac0 = eve::log_abs(c0); auto ang = eve::if_else(kyosu::is_real(c1), eve::zero, ic1*lgac0); auto mod = eve::pow(c0, rc1); - auto r1 = kyosu::polar(mod, ang); + auto r1 = kyosu::to_polar(mod, ang); auto isposc0 = eve::is_positive(c0); if (eve::all(isposc0)) { diff --git a/include/kyosu/types/impl/quaternion/specific.hpp b/include/kyosu/types/impl/quaternion/specific.hpp index 7b1f8a48..c3a830eb 100644 --- a/include/kyosu/types/impl/quaternion/specific.hpp +++ b/include/kyosu/types/impl/quaternion/specific.hpp @@ -291,13 +291,13 @@ namespace kyosu::_ return wp; } - template + template KYOSU_FORCEINLINE constexpr auto dispatch(eve::tag_of const& , Z const & q , std::span const & v) noexcept { - return rot_vec(q, v, _::norming{}); + return rotate_vec(q, v, _::norming{}); } template @@ -338,12 +338,13 @@ namespace kyosu::_ template KYOSU_FORCEINLINE constexpr auto dispatch(eve::tag_of const& - , Z1 const& z1, Z2 z2, T const & t + , Z1 z1, Z2 z2, T const & t ) noexcept { EVE_ASSERT(eve::all(is_unitary(z1) && is_unitary(z2)), "quaternion parameters must be unitary"); - z2 = kyosu::if_else(eve::is_gez(kyosu::dot(z1, z2)), z2, -z2); - return z1*kyosu::pow(kyosu::conj(z1)*z2, t); + auto gez = eve::is_gez(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/types/impl/trigo.hpp b/include/kyosu/types/impl/trigo.hpp index 7dd3f0f8..9883b24c 100644 --- a/include/kyosu/types/impl/trigo.hpp +++ b/include/kyosu/types/impl/trigo.hpp @@ -281,4 +281,92 @@ namespace kyosu::_ 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); } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return eve::half(as(real(z)))*(log((inc(z))-log(dec(z)))); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return eve::half(as(real(z)))*(log((dec(z)-log(inc(z))))); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return log(z+sqrt(inc(z))*sqrt(dec(z))); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return log(z+sqrt(inc(sqr(z)))); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return acosh(rec(z)); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return sinh(rec(z)); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + auto s = sign(pure(z)); + return s*asinh(z*s); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return sign(pure(z))*acosh(z); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + auto s = sign(pure(z)); + return s*atanh(z*s); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + auto s = sign(pure(z)); + return s*acoth(z*s); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return acos(rec(z)); + } + + template + KYOSU_FORCEINLINE constexpr + auto dispatch(eve::tag_of const&, C const& z) noexcept + { + return asin(rec(z)); + } + } diff --git a/include/kyosu/types/impl/trigo_pi.hpp b/include/kyosu/types/impl/trigo_pi.hpp index 6433b61b..6d3e2d6d 100644 --- a/include/kyosu/types/impl/trigo_pi.hpp +++ b/include/kyosu/types/impl/trigo_pi.hpp @@ -103,7 +103,7 @@ namespace kyosu::_ if constexpr(concepts::complex ) { auto [rz, iz] = z; - iz *= eve::pi(as(iz)); + iz *= eve::pi(eve::as(iz)); auto [s, c] = eve::sinpicospi(rz); auto [sh, ch] = eve::sinhcosh(iz); auto rc = c*ch; @@ -118,19 +118,19 @@ namespace kyosu::_ auto cpi = kyosu::complex(rc, ic); auto arz = -kyosu::imag(z); auto aiz = kyosu::real(z); - arz*= eve::pi(as(arz)); + 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 = if_else(eve::is_infinite(aiz) && eve::is_not_finite(arz), arz, rs); - is = if_else(eve::is_infinite(aiz) && eve::is_nan(arz), iz, is); - rs = if_else(eve::is_nan(aiz), arz, rs); - is = if_else(eve::is_nan(aiz), arz, is); - is = if_else(eve::is_eqz(aiz), eve::zero, is); - rs = if_else(eve::is_eqz(arz), eve::zero, rs); + 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}; diff --git a/test/doc/conversions.cpp b/test/doc/conversions.cpp deleted file mode 100644 index 08143412..00000000 --- a/test/doc/conversions.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft a = { 0.0f, 1.0f, -1.0f, 0.5f}; - wide_ft b = { 2.0f , -1.0, -5.0, 0.0}; - wide_ft c = { 1.0f, -3.0f, -4.0f, 1.5f}; - wide_ft d = { -2.0, 1.5f, 2.3f, 6.7f}; - wide_ft r1= { 1.0f, 2.0f, 3.0f, 0.0f}; - wide_ft r2= { 0.0f, 3.0f, 4.0f, 10.0f}; - - std::cout - << "---- simd" << std::endl - << "<- a = " << a << std::endl - << "<- b = " << b << std::endl - << "<- c = " << c << std::endl - << "<- d = " << d << std::endl - << "<- r1 = " << c << std::endl - << "<- r2 = " << d << std::endl - << "-> cylindrical(r1, b, c, d) = " << eve::from_cylindrical(r1, b, c, d) << std::endl - << "-> cylindrospherical(r1, r2, c, d) = " << eve::from_cylindrospherical(r1, r2, c, d) << std::endl - << "-> multipolar(r1, c, r2, d) = " << eve::from_multipolar(r1, c, r2, d) << std::endl - << "-> semipolar(r1, b, c, d) = " << eve::from_semipolar(r1, b, c, d) << std::endl - << "-> spherical(r1, b, c, d) = " << eve::from_spherical(r1, b, c, d) << std::endl - ; - - return 0; -} diff --git a/test/doc/dot.cpp b/test/doc/dot.cpp index 135e6227..6030af48 100644 --- a/test/doc/dot.cpp +++ b/test/doc/dot.cpp @@ -40,6 +40,7 @@ int main() std::cout << wq0 << ", " << q1 << " -> " << dot(wq0, q1) << "\n"; std::cout << wq0 << ", " << c1 << " -> " << dot(wq0, c1) << "\n"; std::cout << wq0 << ", " << e1 << " -> " << dot(wq0, e1) << "\n"; + std::cout << q0 << ", " << we1 << " -> " << dot(q0, we1) << "\n"; return 0; } diff --git a/test/doc/exp_i.cpp b/test/doc/exp_i.cpp new file mode 100644 index 00000000..dd1db451 --- /dev/null +++ b/test/doc/exp_i.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::exp_i; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << exp_i(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << exp_i(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << exp_i(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << exp_i(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/exp_ipi.cpp b/test/doc/exp_ipi.cpp new file mode 100644 index 00000000..497c9d62 --- /dev/null +++ b/test/doc/exp_ipi.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::exp_ipi; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << exp_ipi(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << exp_ipi(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << exp_ipi(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << exp_ipi(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/from_angle_axis.cpp b/test/doc/from_angle_axis.cpp new file mode 100644 index 00000000..0613e52e --- /dev/null +++ b/test/doc/from_angle_axis.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +int main() +{ + using kyosu::from_angle_axis; + using kyosu::complex_t; + using kyosu::quaternion_t; + + + auto theta = eve::pio_3(eve::as()); + std::array ax{1., 2., 3.}; + + std::cout << " <- theta = " << theta << std::endl; + std::cout << " <- axis = (" << ax[0] << ", " << ax[1] << ", " << ax[2] << ")" << std::endl; + auto q = kyosu::from_angle_axis(theta, ax); + std::cout << " -> " << kyosu::from_angle_axis(theta, ax) << "\n"; + auto [aa, axx] = kyosu::to_angle_axis(q); + std::cout << " ->theta = " << aa << std::endl; + std::cout << " -> axis = (" << axx[0] << ", " << axx[1] << ", " << axx[2] << ")" << std::endl; + + return 0; +} diff --git a/test/doc/from_cylindrospherical.cpp b/test/doc/from_cylindrospherical.cpp new file mode 100644 index 00000000..31e9f193 --- /dev/null +++ b/test/doc/from_cylindrospherical.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +int main() +{ + using kyosu::from_cylindrospherical; + using kyosu::quaternion_t; + + auto radius = 2.0; + auto t = eve::pio_3(eve::as(radius)); + auto longitude = eve::pio_4(eve::as(radius)); + auto latitude = eve::pio_2(eve::as(radius)); + std::cout << " <- radius " << radius << std::endl; + std::cout << " <- t " << t << std::endl; + std::cout << " <- longitude " << longitude << std::endl; + std::cout << " <- latitude " << latitude << std::endl; + std::cout << " -> " << from_cylindrospherical(radius, t, longitude, latitude) << "\n"; + + return 0; +} diff --git a/test/doc/from_multipolar.cpp b/test/doc/from_multipolar.cpp new file mode 100644 index 00000000..40b731d8 --- /dev/null +++ b/test/doc/from_multipolar.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +int main() +{ + using kyosu::from_multipolar; + using kyosu::complex_t; + using kyosu::quaternion_t; + + auto r1 = 2.0; + auto t1 = eve::pio_3(eve::as(r1)); + auto r2 = 3.0; + auto t2 = eve::pio_2(eve::as(r1)); + std::cout << " <- r1 " << r1 << std::endl; + std::cout << " <- t1 " << t1<< std::endl; + std::cout << " <- r2 " << r2<< std::endl; + std::cout << " <- t2 " << t2<< std::endl; + std::cout << " -> " << from_multipolar(r1, t1, r2, t2) << "\n"; + + return 0; +} diff --git a/test/doc/from_polar.cpp b/test/doc/from_polar.cpp new file mode 100644 index 00000000..1d1bd3df --- /dev/null +++ b/test/doc/from_polar.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +int main() +{ + using kyosu::from_polar; + using kyosu::complex_t; + using kyosu::quaternion_t; + + + auto theta = eve::pio_3(eve::as()); + auto rho = 3.0; + + std::cout << " <- theta = " << theta << std::endl; + std::cout << " <- rho = " << rho << std::endl; + std::cout << " -> " << kyosu::from_polar(theta, rho) << "\n"; + + return 0; +} diff --git a/test/doc/from_rotation_matrix.cpp b/test/doc/from_rotation_matrix.cpp new file mode 100644 index 00000000..8a411fd0 --- /dev/null +++ b/test/doc/from_rotation_matrix.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +int main() +{ + using kyosu::to_rotation_matrix; + using kyosu::from_rotation_matrix; + using kyosu::complex_t; + using kyosu::quaternion_t; + using q_t = kyosu::quaternion_t; + + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q0 = kyosu::sign(q0); //normalization is optional + auto m = to_rotation_matrix(q0); + std::cout << "q0 = " << q0 << std::endl; + std::cout << "m = to_rotation_matrix(q0) = \n"; + for(int i=0; i <3 ; ++i) + { + std::cout << " "; + for(int j=0; j < 2 ; ++j) + { + std::cout << m[i][j] << ", "; + } + std::cout << m[i][2] << "\n"; + } + std::cout << "from_rotation_matrix(m) = " << from_rotation_matrix(m) << std::endl; + + return 0; +} diff --git a/test/doc/from_semipolar.cpp b/test/doc/from_semipolar.cpp new file mode 100644 index 00000000..f45a1e7d --- /dev/null +++ b/test/doc/from_semipolar.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +int main() +{ + using kyosu::from_semipolar; + using kyosu::complex_t; + using kyosu::quaternion_t; + + auto r1 = 2.0; + auto t1 = eve::pio_3(eve::as(r1)); + auto h1 = 3.0; + auto h2 = eve::pio_2(eve::as(r1)); + std::cout << " <- r1 " << r1 << std::endl; + std::cout << " <- t1 " << t1<< std::endl; + std::cout << " <- h1 " << h1<< std::endl; + std::cout << " <- h2 " << h2<< std::endl; + std::cout << " -> " << from_semipolar(r1, t1, h1, h2) << "\n"; + + return 0; +} diff --git a/test/doc/from_spherical.cpp b/test/doc/from_spherical.cpp new file mode 100644 index 00000000..8ea11fbe --- /dev/null +++ b/test/doc/from_spherical.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +int main() +{ + using kyosu::from_spherical; + using kyosu::complex_t; + using kyosu::quaternion_t; + + auto r = 2.0; + auto theta = eve::pio_3(eve::as(r)); + auto phi1 = eve::pio_4(eve::as(r)); + auto phi2 = eve::pio_2(eve::as(r)); + std::cout << " <- r " << r << std::endl; + std::cout << " <- theta " << theta<< std::endl; + std::cout << " <- phi1 " << phi1<< std::endl; + std::cout << " <- phi2 " << phi2<< std::endl; + std::cout << " -> " << from_spherical(r, theta, phi1, phi2) << "\n"; + + return 0; +} diff --git a/test/doc/ldiv.cpp b/test/doc/ldiv.cpp new file mode 100644 index 00000000..5e8f8a7a --- /dev/null +++ b/test/doc/ldiv.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +int main() +{ + using kyosu::ldiv; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << ldiv(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << ldiv(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << ldiv(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << ldiv(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << ldiv(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << ldiv(wc0, wc1) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + std::cout << q0 << ", " << q1 << " -> " << ldiv(q0, q1) << "\n"; + std::cout << q0 << ", " << q0 << " -> " << ldiv(q0, q0) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << " -> " << ldiv(wq0, wq1) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << kyosu::ldiv(c0, q1) << std::endl; + std::cout << kyosu::ldiv(e0, q1) << std::endl; + std::cout << kyosu::ldiv(c0, wq1) << std::endl; + std::cout << kyosu::ldiv(we0, q1) << std::endl; + + return 0; +} diff --git a/test/doc/lerp.cpp b/test/doc/lerp.cpp new file mode 100644 index 00000000..12268eb3 --- /dev/null +++ b/test/doc/lerp.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +int main() +{ + using kyosu::lerp; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + e_t t(0.3); + std::cout << e0 << ", " << e1 << ", " << t << " -> " << lerp(e0, e1, t) << "\n"; + std::cout << e0 << ", " << e0 << ", " << t << " -> " << lerp(e0, e0, t) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << ", " << t<< " -> " << lerp(we0, we1, t) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << ", " << t << " -> " << lerp(c0, c1, t) << "\n"; + std::cout << c0 << ", " << c0 << ", " << t << " -> " << lerp(c0, c0, t) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << ", " << t << " -> " << lerp(wc0, wc1, t) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + std::cout << q0 << ", " << q1 << ", " << t << " -> " << lerp(q0, q1, t) << "\n"; + std::cout << q0 << ", " << q0 << ", " << t << " -> " << lerp(q0, q0, t) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << ", " << t << " -> " << lerp(wq0, wq1, t) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << c0 << ", " << q1 << ", " << t << " -> " << kyosu::lerp(c0, q1, t) << std::endl; + std::cout << e0 << ", " << q1 << ", " << t << " -> " << kyosu::lerp(e0, q1, t) << std::endl; + std::cout << c0 << ", " << wq1<< ", " << t << " -> " << kyosu::lerp(c0, wq1, t) << std::endl; + std::cout << we0<< ", " << q1 << ", " << t << " -> " << kyosu::lerp(we0, q1, t) << std::endl; + + return 0; +} diff --git a/test/doc/lrising_factorial.cpp b/test/doc/lrising_factorial.cpp new file mode 100644 index 00000000..0ffada12 --- /dev/null +++ b/test/doc/lrising_factorial.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +int main() +{ + using kyosu::lrising_factorial; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << lrising_factorial(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << lrising_factorial(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << lrising_factorial(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << lrising_factorial(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << lrising_factorial(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << lrising_factorial(wc0, wc1) << "\n"; + + return 0; +} diff --git a/test/doc/pow.cpp b/test/doc/pow.cpp new file mode 100644 index 00000000..66b84913 --- /dev/null +++ b/test/doc/pow.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +int main() +{ + using kyosu::pow; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << pow(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << pow(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << pow(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << pow(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << pow(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << pow(wc0, wc1) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + std::cout << q0 << ", " << q1 << " -> " << pow(q0, q1) << "\n"; + std::cout << q0 << ", " << q0 << " -> " << pow(q0, q0) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << " -> " << pow(wq0, wq1) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << kyosu::pow(c0, q1) << std::endl; + std::cout << kyosu::pow(e0, q1) << std::endl; + std::cout << kyosu::pow(c0, wq1) << std::endl; + std::cout << kyosu::pow(we0, q1) << std::endl; + + return 0; +} diff --git a/test/doc/pow1p.cpp b/test/doc/pow1p.cpp new file mode 100644 index 00000000..1c1f5423 --- /dev/null +++ b/test/doc/pow1p.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +int main() +{ + using kyosu::pow1p; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << pow1p(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << pow1p(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << pow1p(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << pow1p(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << pow1p(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << pow1p(wc0, wc1) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + std::cout << q0 << ", " << q1 << " -> " << pow1p(q0, q1) << "\n"; + std::cout << q0 << ", " << q0 << " -> " << pow1p(q0, q0) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << " -> " << pow1p(wq0, wq1) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << kyosu::pow1p(c0, q1) << std::endl; + std::cout << kyosu::pow1p(e0, q1) << std::endl; + std::cout << kyosu::pow1p(c0, wq1) << std::endl; + std::cout << kyosu::pow1p(we0, q1) << std::endl; + + return 0; +} diff --git a/test/doc/pow_abs.cpp b/test/doc/pow_abs.cpp new file mode 100644 index 00000000..814b0ce0 --- /dev/null +++ b/test/doc/pow_abs.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +int main() +{ + using kyosu::pow_abs; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << pow_abs(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << pow_abs(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << pow_abs(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << pow_abs(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << pow_abs(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << pow_abs(wc0, wc1) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + std::cout << q0 << ", " << q1 << " -> " << pow_abs(q0, q1) << "\n"; + std::cout << q0 << ", " << q0 << " -> " << pow_abs(q0, q0) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << " -> " << pow_abs(wq0, wq1) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << kyosu::pow_abs(c0, q1) << std::endl; + std::cout << kyosu::pow_abs(e0, q1) << std::endl; + std::cout << kyosu::pow_abs(c0, wq1) << std::endl; + std::cout << kyosu::pow_abs(we0, q1) << std::endl; + + return 0; +} diff --git a/test/doc/powm1.cpp b/test/doc/powm1.cpp new file mode 100644 index 00000000..996c7d45 --- /dev/null +++ b/test/doc/powm1.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +int main() +{ + using kyosu::powm1; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << powm1(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << powm1(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << powm1(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << powm1(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << powm1(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << powm1(wc0, wc1) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + std::cout << q0 << ", " << q1 << " -> " << powm1(q0, q1) << "\n"; + std::cout << q0 << ", " << q0 << " -> " << powm1(q0, q0) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << " -> " << powm1(wq0, wq1) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << kyosu::powm1(c0, q1) << std::endl; + std::cout << kyosu::powm1(e0, q1) << std::endl; + std::cout << kyosu::powm1(c0, wq1) << std::endl; + std::cout << kyosu::powm1(we0, q1) << std::endl; + + return 0; +} diff --git a/test/doc/radinpi.cpp b/test/doc/radinpi.cpp new file mode 100644 index 00000000..717ee83b --- /dev/null +++ b/test/doc/radinpi.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::radinpi; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << radinpi(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << radinpi(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << radinpi(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << radinpi(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/rec.cpp b/test/doc/rec.cpp new file mode 100644 index 00000000..9c3991fa --- /dev/null +++ b/test/doc/rec.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::rec; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << rec(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << rec(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << rec(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << rec(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/rising_factorial.cpp b/test/doc/rising_factorial.cpp new file mode 100644 index 00000000..d90d62de --- /dev/null +++ b/test/doc/rising_factorial.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +int main() +{ + using kyosu::rising_factorial; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << rising_factorial(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << rising_factorial(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << rising_factorial(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << rising_factorial(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << rising_factorial(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << rising_factorial(wc0, wc1) << "\n"; + return 0; +} diff --git a/test/doc/rot_angle.cpp b/test/doc/rot_angle.cpp new file mode 100644 index 00000000..a6fff313 --- /dev/null +++ b/test/doc/rot_angle.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::rot_angle; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << rot_angle(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << rot_angle(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << rot_angle(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << rot_angle(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/rot_axis.cpp b/test/doc/rot_axis.cpp new file mode 100644 index 00000000..bbbdade9 --- /dev/null +++ b/test/doc/rot_axis.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +int main() +{ + using kyosu::rot_axis; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + auto v = rot_axis(kyosu::complex_t(3.5f,-2.9f)); + std::cout << 72.9f << " -> (" << v[0] << ", " << v[1] << ", " << v[2] << ")\n"; + + std::cout << "Complex: "; + auto vc = rot_axis(kyosu::complex_t(3.5f,-2.9f)); + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> (" << vc[0] << ", " << vc[1] << ", " << vc[2] << ")\n"; + + std::cout << "Quaternion: "; + auto vq = rot_axis(kyosu::quaternion_t(1.,2.,3.,4.)); + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << vq[0] << ", " << vq[1] << ", " << vq[2] << ")\n"; + + return 0; +} diff --git a/test/doc/rotate_vec.cpp b/test/doc/rotate_vec.cpp new file mode 100644 index 00000000..f6a23cab --- /dev/null +++ b/test/doc/rotate_vec.cpp @@ -0,0 +1,19 @@ +#include +#include +#include + +int main() +{ + using kyosu::rotate_vec; + + auto theta = eve::pio_3(eve::as()); + std::array ax{1., 2., 3.}; + std::array v{ 1.5, 2.0, -3.0}; + auto q = kyosu::from_angle_axis(theta, ax); + std::cout << " v " << v[0] << ", " << v[1] << ", " << v[2] << ")\n"; + std::cout << " q " << q << std::endl; + auto rv = kyosu::rotate_vec(q, std::span(v)); + std::cout << " rotate_vec(q, v) " << " -> (" << rv[0] << ", " << rv[1] << ", " << rv[2] << ")\n"; + + return 0; +} diff --git a/test/doc/sec.cpp b/test/doc/sec.cpp new file mode 100644 index 00000000..e32da4f4 --- /dev/null +++ b/test/doc/sec.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sec; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sec(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sec(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sec(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sec(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sech.cpp b/test/doc/sech.cpp new file mode 100644 index 00000000..6a9118bf --- /dev/null +++ b/test/doc/sech.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sech; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sech(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sech(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sech(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sech(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/secpi.cpp b/test/doc/secpi.cpp new file mode 100644 index 00000000..aa5a81d1 --- /dev/null +++ b/test/doc/secpi.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::secpi; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << secpi(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << secpi(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << secpi(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << secpi(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sign.cpp b/test/doc/sign.cpp new file mode 100644 index 00000000..c20aad67 --- /dev/null +++ b/test/doc/sign.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sign; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sign(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sign(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sign(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sign(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sin.cpp b/test/doc/sin.cpp new file mode 100644 index 00000000..c4287753 --- /dev/null +++ b/test/doc/sin.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sin; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sin(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sin(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sin(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sin(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sinc.cpp b/test/doc/sinc.cpp new file mode 100644 index 00000000..4c25ead6 --- /dev/null +++ b/test/doc/sinc.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sinc; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sinc(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sinc(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sinc(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sinc(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sincos.cpp b/test/doc/sincos.cpp new file mode 100644 index 00000000..71639c53 --- /dev/null +++ b/test/doc/sincos.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sincos; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sincos(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sincos(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sincos(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sincos(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sinh.cpp b/test/doc/sinh.cpp new file mode 100644 index 00000000..dccca33b --- /dev/null +++ b/test/doc/sinh.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sinh; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sinh(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sinh(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sinh(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sinh(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sinhcosh.cpp b/test/doc/sinhcosh.cpp new file mode 100644 index 00000000..cd8333b9 --- /dev/null +++ b/test/doc/sinhcosh.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sinhcosh; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sinhcosh(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sinhcosh(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sinhcosh(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sinhcosh(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sinpi.cpp b/test/doc/sinpi.cpp new file mode 100644 index 00000000..a218a3a7 --- /dev/null +++ b/test/doc/sinpi.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sinpi; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sinpi(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sinpi(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sinpi(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sinpi(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sinpicospi.cpp b/test/doc/sinpicospi.cpp new file mode 100644 index 00000000..3ee86d4c --- /dev/null +++ b/test/doc/sinpicospi.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sinpicospi; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sinpicospi(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sinpicospi(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sinpicospi(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sinpicospi(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/slerp.cpp b/test/doc/slerp.cpp new file mode 100644 index 00000000..e0afad2d --- /dev/null +++ b/test/doc/slerp.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +int main() +{ + using kyosu::slerp; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + using kyosu::sign; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(-1); + e_t t(0.3); + std::cout << e0 << ", " << e1 << ", " << t << " -> " << slerp(e0, e1, t) << "\n"; + std::cout << e0 << ", " << e0 << ", " << t << " -> " << slerp(e0, e0, t) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << ", " << t<< " -> " << slerp(we0, we1, t) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + c0 = sign(c0); + c1 = sign(c1); + std::cout << c0 << ", " << c1 << ", " << t << " -> " << slerp(c0, c1, t) << "\n"; + std::cout << c0 << ", " << c0 << ", " << t << " -> " << slerp(c0, c0, t) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << ", " << t << " -> " << slerp(wc0, wc1, t) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + q0 = sign(q0); + q1 = sign(q1); + std::cout << q0 << ", " << q1 << ", " << t << " -> " << slerp(q0, q1, t) << "\n"; + std::cout << q0 << ", " << q0 << ", " << t << " -> " << slerp(q0, q0, t) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << ", " << t << " -> " << slerp(wq0, wq1, t) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << c0 << ", " << q1 << ", " << t << " -> " << kyosu::slerp(c0, q1, t) << std::endl; + std::cout << e0 << ", " << q1 << ", " << t << " -> " << kyosu::slerp(e0, q1, t) << std::endl; + std::cout << c0 << ", " << wq1<< ", " << t << " -> " << kyosu::slerp(c0, wq1, t) << std::endl; + std::cout << we0<< ", " << wq1 << ", " << t << " -> " << kyosu::slerp(we0, wq1, t) << std::endl; + std::cout << we0<< ", " << q1 << ", " << t << " -> " << kyosu::slerp(we0, q1, t) << std::endl; + + return 0; +} diff --git a/test/doc/sqr_abs.cpp b/test/doc/sqr_abs.cpp new file mode 100644 index 00000000..dffabd6d --- /dev/null +++ b/test/doc/sqr_abs.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sqr_abs; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sqr_abs(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sqr_abs(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sqr_abs(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sqr_abs(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/sqrt.cpp b/test/doc/sqrt.cpp new file mode 100644 index 00000000..ff63bb95 --- /dev/null +++ b/test/doc/sqrt.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::sqrt; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << sqrt(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << sqrt(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << sqrt(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << sqrt(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/tan.cpp b/test/doc/tan.cpp new file mode 100644 index 00000000..3034908c --- /dev/null +++ b/test/doc/tan.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::tan; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << tan(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << tan(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << tan(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << tan(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/tanh.cpp b/test/doc/tanh.cpp new file mode 100644 index 00000000..99051b87 --- /dev/null +++ b/test/doc/tanh.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::tanh; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << tanh(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << tanh(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << tanh(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << tanh(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/tanpi.cpp b/test/doc/tanpi.cpp new file mode 100644 index 00000000..89e6a129 --- /dev/null +++ b/test/doc/tanpi.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +int main() +{ + using kyosu::tanpi; + using kyosu::complex_t; + using kyosu::quaternion_t; + + std::cout << "Real: "; + std::cout << 72.9f << " -> " << tanpi(72.9f) << "\n"; + + std::cout << "Complex: "; + std::cout << kyosu::complex_t(3.5f,-2.9f) << " -> " << tanpi(kyosu::complex_t(3.5f,-2.9f)) << "\n"; + + std::cout << "Quaternion: "; + std::cout << kyosu::quaternion_t(1.,2.,3.,4.) << " -> " << tanpi(kyosu::quaternion_t(1.,2.,3.,4.)) << "\n"; + + std::cout << "SIMD: "; + using wc_t = eve::wide, eve::fixed<2>>; + std::cout << wc_t(kyosu::complex_t(1.3,-3.7)) << " -> " << tanpi(wc_t(kyosu::complex_t(1.3,-3.7))) << "\n"; + + return 0; +} diff --git a/test/doc/to_angle_axis.cpp b/test/doc/to_angle_axis.cpp new file mode 100644 index 00000000..78db745a --- /dev/null +++ b/test/doc/to_angle_axis.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +int main() +{ + using kyosu::to_angle_axis; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + auto [ae, axe] = to_angle_axis(e0); + std::cout << e0 << " -> " << ae << ", (" << axe[0] << ", " << axe[1] << ", " << axe[2] << ") " "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + auto [ac, axc] = to_angle_axis(c0); + std::cout << c0 << " -> " << ac << ", (" << axc[0] << ", " << axc[1] << ", " << axc[2] << ") " "\n"; + + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + auto [aq, axq] = to_angle_axis(q0); + std::cout << q0 << " -> " << aq << ", (" << axq[0] << ", " << axq[1] << ", " << axq[2] << ") " "\n"; + + return 0; +} diff --git a/test/doc/to_cylindrical.cpp b/test/doc/to_cylindrical.cpp new file mode 100644 index 00000000..a9ae6bb0 --- /dev/null +++ b/test/doc/to_cylindrical.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +int main() +{ + using kyosu::to_cylindrical; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + std::cout << e0 << " -> " << to_cylindrical(e0) << "\n"; + we_t we0(e0); + std::cout << we0 << " -> " << to_cylindrical(we0) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + std::cout << c0 << " -> " << to_cylindrical(c0) << "\n"; + wc_t wc0(c0); + std::cout << wc0 << " -> " << to_cylindrical(wc0) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + std::cout << q0 << " -> " << to_cylindrical(q0) << "\n"; + wq_t wq0(q0); + std::cout << wq0 << " -> " << to_cylindrical(wq0) << "\n"; + + return 0; +} diff --git a/test/doc/to_euler.cpp b/test/doc/to_euler.cpp new file mode 100644 index 00000000..fde43861 --- /dev/null +++ b/test/doc/to_euler.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +int main() +{ + using kyosu::average; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << average(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << average(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << average(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << average(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << average(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << average(wc0, wc1) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + std::cout << q0 << ", " << q1 << " -> " << average(q0, q1) << "\n"; + std::cout << q0 << ", " << q0 << " -> " << average(q0, q0) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << " -> " << average(wq0, wq1) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << kyosu::average(c0, q1) << std::endl; + std::cout << kyosu::average(e0, q1) << std::endl; + std::cout << kyosu::average(c0, wq1) << std::endl; + std::cout << kyosu::average(we0, q1) << std::endl; + + return 0; +} diff --git a/test/doc/to_multipolar.cpp b/test/doc/to_multipolar.cpp new file mode 100644 index 00000000..fde43861 --- /dev/null +++ b/test/doc/to_multipolar.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +int main() +{ + using kyosu::average; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(2); + std::cout << e0 << ", " << e1 << " -> " << average(e0, e1) << "\n"; + std::cout << e0 << ", " << e0 << " -> " << average(e0, e0) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << ", " << we1 << " -> " << average(we0, we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + c_t c1(5, 9); + std::cout << c0 << ", " << c1 << " -> " << average(c0, c1) << "\n"; + std::cout << c0 << ", " << c0 << " -> " << average(c0, c0) << "\n"; + wc_t wc0(c0, c1); + wc_t wc1(c1, c1); + std::cout << wc0 << ", " << wc1 << " -> " << average(wc0, wc1) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + q_t q1(5, 9, 6, 7); + std::cout << q0 << ", " << q1 << " -> " << average(q0, q1) << "\n"; + std::cout << q0 << ", " << q0 << " -> " << average(q0, q0) << "\n"; + wq_t wq0(q0, q1); + wq_t wq1(q1, q1); + std::cout << wq0 << ", " << wq1 << " -> " << average(wq0, wq1) << "\n"; + + std::cout << "Mixed: "<< "\n"; + std::cout << kyosu::average(c0, q1) << std::endl; + std::cout << kyosu::average(e0, q1) << std::endl; + std::cout << kyosu::average(c0, wq1) << std::endl; + std::cout << kyosu::average(we0, q1) << std::endl; + + return 0; +} diff --git a/test/doc/to_polar.cpp b/test/doc/to_polar.cpp new file mode 100644 index 00000000..e4b2eda3 --- /dev/null +++ b/test/doc/to_polar.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +int main() +{ + using kyosu::to_polar; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + e_t e1(-2); + std::cout << e0 << " -> " << to_polar(e0) << "\n"; + std::cout << e1 << " -> " << to_polar(e1) << "\n"; + we_t we0(e0); + we_t we1(e1); + std::cout << we0 << " -> " << to_polar(we0) << "\n"; + std::cout << we1 << " -> " << to_polar(we1) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(3, -4); + std::cout << c0 << " -> " << to_polar(c0) << "\n"; + wc_t wc0(c0); + std::cout << wc0 << " -> " << to_polar(wc0) << "\n"; + + return 0; +} diff --git a/test/doc/to_rotation_matrix b/test/doc/to_rotation_matrix new file mode 100644 index 00000000..a9ae6bb0 --- /dev/null +++ b/test/doc/to_rotation_matrix @@ -0,0 +1,36 @@ +#include +#include +#include + +int main() +{ + using kyosu::to_cylindrical; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + std::cout << e0 << " -> " << to_cylindrical(e0) << "\n"; + we_t we0(e0); + std::cout << we0 << " -> " << to_cylindrical(we0) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + std::cout << c0 << " -> " << to_cylindrical(c0) << "\n"; + wc_t wc0(c0); + std::cout << wc0 << " -> " << to_cylindrical(wc0) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + std::cout << q0 << " -> " << to_cylindrical(q0) << "\n"; + wq_t wq0(q0); + std::cout << wq0 << " -> " << to_cylindrical(wq0) << "\n"; + + return 0; +} diff --git a/test/doc/to_rotation_matrix.cpp b/test/doc/to_rotation_matrix.cpp new file mode 100644 index 00000000..e151cc1f --- /dev/null +++ b/test/doc/to_rotation_matrix.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +int main() +{ + using kyosu::to_rotation_matrix; + using kyosu::complex_t; + using kyosu::quaternion_t; + using q_t = kyosu::quaternion_t; + + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + auto m = to_rotation_matrix(q0); + std::cout << "q0 = " << q0 << std::endl; + std::cout << "to_rotation_matrix(q0) = \n"; + for(int i=0; i <3 ; ++i) + { + std::cout << " "; + for(int j=0; j < 2 ; ++j) + { + std::cout << m[i][j] << ", "; + } + std::cout << m[i][2] << "\n"; + } + return 0; +} diff --git a/test/doc/to_semipolar.cpp b/test/doc/to_semipolar.cpp new file mode 100644 index 00000000..b0b75fc8 --- /dev/null +++ b/test/doc/to_semipolar.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +int main() +{ + using kyosu::to_semipolar; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + std::cout << e0 << " -> " << to_semipolar(e0) << "\n"; + we_t we0(e0); + std::cout << we0 << " -> " << to_semipolar(we0) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + std::cout << c0 << " -> " << to_semipolar(c0) << "\n"; + wc_t wc0(c0); + std::cout << wc0 << " -> " << to_semipolar(wc0) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + std::cout << q0 << " -> " << to_semipolar(q0) << "\n"; + wq_t wq0(q0); + std::cout << wq0 << " -> " << to_semipolar(wq0) << "\n"; + + return 0; +} diff --git a/test/doc/to_spherical.cpp b/test/doc/to_spherical.cpp new file mode 100644 index 00000000..b88c479b --- /dev/null +++ b/test/doc/to_spherical.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +int main() +{ + using kyosu::to_spherical; + using kyosu::complex_t; + using kyosu::quaternion_t; + using e_t = float; + using c_t = kyosu::complex_t; + using q_t = kyosu::quaternion_t; + using we_t = eve::wide>; + using wc_t = eve::wide, eve::fixed<2>>; + using wq_t = eve::wide, eve::fixed<2>>; + + std::cout << "Real: "<< "\n"; + e_t e0(1); + std::cout << e0 << " -> " << to_spherical(e0) << "\n"; + we_t we0(e0); + std::cout << we0 << " -> " << to_spherical(we0) << "\n"; + + std::cout << "Complex: "<< "\n"; + c_t c0(1, 5); + std::cout << c0 << " -> " << to_spherical(c0) << "\n"; + wc_t wc0(c0); + std::cout << wc0 << " -> " << to_spherical(wc0) << "\n"; + + std::cout << "Quaternion: "<< "\n"; + q_t q0(1, 5, 2, 3); + std::cout << q0 << " -> " << to_spherical(q0) << "\n"; + wq_t wq0(q0); + std::cout << wq0 << " -> " << to_spherical(wq0) << "\n"; + + return 0; +}