Skip to content

Commit

Permalink
[FEATURES] Implemebnts dec, inc, minus, oneminus and ++/--
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap authored Aug 23, 2023
1 parent 8b8ab7e commit 57b8c41
Show file tree
Hide file tree
Showing 15 changed files with 656 additions and 4 deletions.
10 changes: 7 additions & 3 deletions include/kyosu/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
#include <kyosu/functions/abs.hpp>
#include <kyosu/functions/ceil.hpp>
#include <kyosu/functions/conj.hpp>
#include <kyosu/functions/dec.hpp>
#include <kyosu/functions/dist.hpp>
#include <kyosu/functions/floor.hpp>
#include <kyosu/functions/frac.hpp>
#include <kyosu/functions/if_else.hpp>
#include <kyosu/functions/inc.hpp>
#include <kyosu/functions/ipart.hpp>
#include <kyosu/functions/is_denormal.hpp>
#include <kyosu/functions/is_finite.hpp>
#include <kyosu/functions/is_equal.hpp>
#include <kyosu/functions/is_eqz.hpp>
#include <kyosu/functions/is_finite.hpp>
#include <kyosu/functions/is_infinite.hpp>
#include <kyosu/functions/is_nan.hpp>
#include <kyosu/functions/is_nez.hpp>
Expand All @@ -30,14 +33,15 @@
#include <kyosu/functions/is_not_finite.hpp>
#include <kyosu/functions/is_not_infinite.hpp>
#include <kyosu/functions/is_not_nan.hpp>
#include <kyosu/functions/ipart.hpp>
#include <kyosu/functions/jpart.hpp>
#include <kyosu/functions/kpart.hpp>
#include <kyosu/functions/lerp.hpp>
#include <kyosu/functions/minus.hpp>
#include <kyosu/functions/nearest.hpp>
#include <kyosu/functions/oneminus.hpp>
#include <kyosu/functions/purepart.hpp>
#include <kyosu/functions/real.hpp>
#include <kyosu/functions/reldist.hpp>
#include <kyosu/functions/sqr.hpp>
#include <kyosu/functions/sqr_abs.hpp>
#include <kyosu/functions/sqr.hpp>
#include <kyosu/functions/trunc.hpp>
73 changes: 73 additions & 0 deletions include/kyosu/functions/dec.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>

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

KYOSU_DEFERS_CALLABLE(dec_);

template<eve::ordered_value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, T const& v) noexcept { return eve::dec(v); }

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_dec(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var dec
//! @brief decrements the argument by 1.
//!
//! **Defined in Header**
//!
//! @code
//! #declude <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr T dec(T z) noexcept;
//! template<eve::ordered_value T> constexpr T dec(T z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z` : Value to decrement.
//!
//! **Return value**
//!
//! Returns its argument minus 1.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/dec.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_dec dec = {};
}
73 changes: 73 additions & 0 deletions include/kyosu/functions/inc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>

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

KYOSU_DEFERS_CALLABLE(inc_);

template<eve::ordered_value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, T const& v) noexcept { return eve::inc(v); }

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_inc(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var inc
//! @brief Increments the argument.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr T inc(T z) noexcept;
//! template<eve::ordered_value T> constexpr T inc(T z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z` : Value to increment.
//!
//! **Return value**
//!
//! Returns its argument plus 1.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/inc.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_inc inc = {};
}
74 changes: 74 additions & 0 deletions include/kyosu/functions/minus.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>

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

KYOSU_DEFERS_CALLABLE(minus_);

template<eve::value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, T const& v) noexcept { return -v; }
// there is no other implementation

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_minus(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var minus
//! @brief Computes the opposite value.
//!
//! **Defined in Header**
//!
//! @code
//! #include <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr T minus(T z) noexcept;
//! template<eve::ordered_value T> constexpr T minus(T z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z` : Value to minusugate.
//!
//! **Return value**
//!
//! Returns the opposite of its argument.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/minus.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_minus minus = {};
}
73 changes: 73 additions & 0 deletions include/kyosu/functions/oneminus.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>

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

KYOSU_DEFERS_CALLABLE(oneminus_);

template<eve::ordered_value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, T const& v) noexcept { return eve::oneminus(v); }

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_oneminus(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var oneminus
//! @brief Computes the value 1 minus the argument.
//!
//! **Defined in Header**
//!
//! @code
//! #oneminuslude <kyosu/functions.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::cayley_dickson T> constexpr T oneminus(T z) noexcept;
//! template<eve::ordered_value T> constexpr T oneminus(T z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z` : argument.
//!
//! **Return value**
//!
//! Returns 1 minus the argument.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/oneminus.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_oneminus oneminus = {};
}
26 changes: 26 additions & 0 deletions include/kyosu/types/cayley_dickson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ namespace kyosu
/// Construct a Caley-dickson abstraction from a properly sized product_type
constexpr cayley_dickson(kumi::sized_product_type<N> auto const& vs) : contents{vs} {}

//==================================================================================================================
// ++/--
//==================================================================================================================

//! Pre-incrementation operator
KYOSU_FORCEINLINE auto& operator++() noexcept { kumi::get<0>(contents)++; return *this; }

//! Pre-decrementation operator
KYOSU_FORCEINLINE auto& operator--() noexcept { kumi::get<0>(contents)--; return *this; }

//! Post-incrementation operator
KYOSU_FORCEINLINE auto operator++(int) noexcept
{
auto that(*this);
this->operator++();
return that;
}

//! Post-decrementation operator
KYOSU_FORCEINLINE auto operator--(int) noexcept
{
auto that(*this);
this->operator--();
return that;
}

//==================================================================================================================
// Main function dispatchers
//==================================================================================================================
Expand Down
Loading

0 comments on commit 57b8c41

Please sign in to comment.