Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cayley/constants #42

Merged
merged 6 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Prefix forms are also provided as `add`, `sub`, `multiply` and `div`. Also plus

The left division sometimes necessary if the dimensionality is greater than 2 is given as `ldiv`.

The left multiplication to the left by i or -i (i*i=-1) can be done calling respectively muli and mulmi

Functions
---------

Expand Down Expand Up @@ -176,3 +178,9 @@ Most **KYOSU** callables are usable with all cayley_dickson types. The exception
| | | |
|-----------|------------|------------|
| [rot_angle](@ref kyosu::rot_angle) | [rot_axis](@ref kyosu::rot_axis) | [rotate_vec](@ref kyosu::rotate_vec) |

* Constant i, j, k and cinf are defined.

* i(as<Z>()) returns a complex of the same underlying type as Z;
* j(as<Z>()) and k(as<Z>()) return a quaternion of the same underlying type as Z;
* cinf(as<Z>()) returns a complex with nan real part and inf imaginary part, that can be roughly taken as a complex-infinity, in the sense that abs is infinite and arg is undefinite (nan).
18 changes: 18 additions & 0 deletions include/kyosu/constants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

//======================================================================================================================
//! @defgroup functions Cayley-Dickson constants
//! @brief non real constants
//======================================================================================================================
#include <kyosu/constants/i.hpp>
#include <kyosu/constants/j.hpp>
#include <kyosu/constants/k.hpp>
#include <kyosu/constants/mi.hpp>
#include <kyosu/constants/cinf.hpp>
79 changes: 79 additions & 0 deletions include/kyosu/constants/cinf.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright: KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>
#include <kyosu/types/complex.hpp>

namespace kyosu::tags
{
struct callable_cinf : eve::elementwise
{
using callable_tag_type = callable_cinf;

KYOSU_DEFERS_CALLABLE(i_);

template<eve::value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, as<T> const& ) noexcept
requires(concepts::cayley_dickson<T> || eve::floating_ordered_value<T>)
{
using u_t = eve::underlying_type_t<T>;
return kyosu::complex(eve::nan(as<u_t>()),eve::inf(as<u_t>()));
}

template<typename T>
KYOSU_FORCEINLINE auto operator()(T const& target) const noexcept -> decltype(eve::tag_invoke(*this, target))
{
return eve::tag_invoke(*this, target);
}

template<typename... T>
eve::unsupported_call<callable_abs(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var i
//! @brief Computes the complex number cinf i.e. complex(nan, inf) in the chosen type.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr as_complex_t<underlying_type_t<T>> cinf(as<T> z) noexcept;
//! template<eve::floating_ordered_value T> constexpr �s_complex_t<underlying_type_t<T>> cinf(as<T> z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z`: Value to process.
//!
//! **Return value**
//!
//! * always returns a complex scalar value cinf such that real(cinf) is a Nan and imag(cinf) is Inf.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/i.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_cinf cinf = {};
}
78 changes: 78 additions & 0 deletions include/kyosu/constants/i.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright: KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>
#include <kyosu/types/complex.hpp>

namespace kyosu::tags
{
struct callable_i : eve::elementwise
{
using callable_tag_type = callable_i;

KYOSU_DEFERS_CALLABLE(i_);

template<eve::value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, as<T> const& ) noexcept
requires(concepts::cayley_dickson<T> || eve::floating_ordered_value<T>)
{
using u_t = eve::underlying_type_t<T>;
return kyosu::complex(u_t(0),u_t(1)); }

template<typename T>
KYOSU_FORCEINLINE auto operator()(T const& target) const noexcept -> decltype(eve::tag_invoke(*this, target))
{
return eve::tag_invoke(*this, target);
}

template<typename... T>
eve::unsupported_call<callable_abs(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var i
//! @brief Computes the complex number i i.e. complex(0, 1) in the chosen type.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr as_complex_t<underlying_type_t<T>> i(as<T> z) noexcept;
//! template<eve::floating_ordered_value T> constexpr �s_complex_t<underlying_type_t<T>> i(as<T> z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z`: Value to process.
//!
//! **Return value**
//!
//! * always returns a complex scalar value i such that real(i) is null and imag(i) is one.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/i.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_i i = {};
}
78 changes: 78 additions & 0 deletions include/kyosu/constants/j.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright: KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>
#include <kyosu/types/complex.hpp>

namespace kyosu::tags
{
struct callable_j : eve::elementwise
{
using callable_tag_type = callable_j;

KYOSU_DEFERS_CALLABLE(j_);

template<eve::value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, as<T> const& ) noexcept
requires(concepts::cayley_dickson<T> || eve::floating_ordered_value<T>)
{
using u_t = eve::underlying_type_t<T>;
return kyosu::quaternion(u_t(0), u_t(0), u_t(1), u_t(0)); }

template<typename T>
KYOSU_FORCEINLINE auto operator()(T const& target) const noexcept -> decltype(eve::tag_invoke(*this, target))
{
return eve::tag_invoke(*this, target);
}

template<typename... T>
eve::unsupported_call<callable_abs(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var i
//! @brief Computes the complex number j i.e. quaternion(0, 0, 1, 0) in the chosen type.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr as_complex_t<underlying_type_t<T>> j(as<T> z) noexcept;
//! template<eve::floating_ordered_value T> constexpr �s_complex_t<underlying_type_t<T>> j(as<T> z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z`: Value to process.
//!
//! **Return value**
//!
//! * always returns a quaternion scalar value j such that all parts are null except the jpart whose value is one.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/i.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_j j = {};
}
78 changes: 78 additions & 0 deletions include/kyosu/constants/k.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright: KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>
#include <kyosu/types/complex.hpp>

namespace kyosu::tags
{
struct callable_k : eve::elementwise
{
using callable_tag_type = callable_k;

KYOSU_DEFERS_CALLABLE(k_);

template<eve::value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, as<T> const& ) noexcept
requires(concepts::cayley_dickson<T> || eve::floating_ordered_value<T>)
{
using u_t = eve::underlying_type_t<T>;
return kyosu::quaternion(u_t(0),u_t(0), u_t(0), u_t(1)); }

template<typename T>
KYOSU_FORCEINLINE auto operator()(T const& target) const noexcept -> decltype(eve::tag_invoke(*this, target))
{
return eve::tag_invoke(*this, target);
}

template<typename... T>
eve::unsupported_call<callable_abs(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var i
//! @brief Computes the complex number k i.e. quaternion(0, 0, 0, 1) in the chosen type.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr as_complex_t<underlying_type_t<T>> k(as<T> z) noexcept;
//! template<eve::floating_ordered_value T> constexpr �s_complex_t<underlying_type_t<T>> k(as<T> z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z`: Value to process.
//!
//! **Return value**
//!
//! * always returns a quaternion scalar value k such that all parts are null exceptthe k part whose value is one.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/i.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_k k = {};
}
Loading