Skip to content

Commit

Permalink
dec inc minus oneminus
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap committed Aug 21, 2023
1 parent 3dc9242 commit 8115d49
Show file tree
Hide file tree
Showing 14 changed files with 633 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/kyosu/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +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/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/jpart.hpp>
#include <kyosu/functions/kpart.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/sqr_abs.hpp>
Expand Down
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 = {};
}
73 changes: 73 additions & 0 deletions include/kyosu/functions/minus.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_minus : eve::elementwise
{
using callable_tag_type = callable_minus;

KYOSU_DEFERS_CALLABLE(minus_);

template<eve::ordered_value T>
static KYOSU_FORCEINLINE auto deferred_call(auto, T const& v) noexcept { return -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_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 = {};
}
32 changes: 32 additions & 0 deletions include/kyosu/types/impl/arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <iostream>

namespace kyosu::_
{
Expand Down Expand Up @@ -95,4 +96,35 @@ namespace kyosu::_
{
return C{kumi::map([](auto const& e) { return eve::frac(e); }, c)};
}

template<concepts::cayley_dickson C>
KYOSU_FORCEINLINE constexpr
auto dispatch(eve::tag_of<kyosu::minus> const&, C const& c) noexcept
{
return -c;
}

template<concepts::cayley_dickson C>
KYOSU_FORCEINLINE constexpr
auto dispatch(eve::tag_of<kyosu::inc> const&, C c) noexcept
{
real(c) = eve::inc(real(c));
return c;
}

template<concepts::cayley_dickson C>
KYOSU_FORCEINLINE constexpr
auto dispatch(eve::tag_of<kyosu::dec> const&, C c) noexcept
{
real(c) = eve::dec(real(c));
return c;
}

template<concepts::cayley_dickson C>
KYOSU_FORCEINLINE constexpr
auto dispatch(eve::tag_of<kyosu::oneminus> const&, C c) noexcept
{
return kyosu::inc(kyosu::minus(c));
}

}
36 changes: 36 additions & 0 deletions test/doc/dec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <kyosu/kyosu.hpp>
#include <eve/wide.hpp>
#include <iostream>

int main()
{
using kyosu::dec;
using kyosu::complex;
using kyosu::quaternion;
using e_t = float;
using c_t = complex<float>;
using q_t = quaternion<float>;
using we_t = eve::wide<e_t, eve::fixed<2>>;
using wc_t = eve::wide<c_t, eve::fixed<2>>;
using wq_t = eve::wide<q_t, eve::fixed<2>>;

std::cout << "Real: \n";
e_t e(72.9f);
we_t we = we_t(e);
std::cout << e << " -> " << dec(e) << "\n";
std::cout << we << " -> " << dec(we) << "\n";

std::cout << "Complex: \n";
c_t c(3.5f,-2.9f);
wc_t wc = wc_t(c);
std::cout << c << " -> " << dec(c) << "\n";
std::cout << wc << " -> " << dec(wc) << "\n";

std::cout << "Quaternion: \n";
q_t q(3.5f,-2.9f, 2.1f, 3.2f);
wq_t wq = wq_t(q);
std::cout << q << " -> " << dec(q) << "\n";
std::cout << wq << " -> " << dec(wq) << "\n";

return 0;
}
Loading

0 comments on commit 8115d49

Please sign in to comment.