kyosu v0.1.0
Complex Without Complexes
Loading...
Searching...
No Matches

◆ sub

auto kyosu::sub = eve::functor<sub_t>
inlineconstexpr

tuple_callable computing the difference of its first argument with the sum of the others.

@subtogroup functions

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto sub(auto ... xs) noexcept; // 1
constexpr auto sub(eve::non_empty_product_type auto const& tup) noexcept; // 2
constexpr auto add[kahan] (/*any of the above overloads*/) noexcept; // 3
// Lanes masking
constexpr auto sub[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 4
constexpr auto sub[logical_value auto m](/*any of the above overloads*/) noexcept; // 4
}
constexpr auto add
tuple_callable computing the sum of its arguments.
Definition add.hpp:87
constexpr auto sub
tuple_callable computing the difference of its first argument with the sum of the others.
Definition sub.hpp:91

! Parameters

 * `xs` :  real or cayley-dickson arguments.
 * `tup` : kumi tuple of arguments.

Return value

  1. The value of the difference of its first argument with the sum of the others.
  2. same on 1. the tuple elements.
  3. kahan algorithm is used to enhance accuracy.
  4. The operation is performed conditionnaly
Note
If all elements are real typed the result will be real typed, using a call to eve::sub
With one cayley_dickson_like parameter sub returns the parameter: use minus or - to return the opposite value.

Example

#include <eve/wide.hpp>
#include <iostream>
#include <kyosu/kyosu.hpp>
int main()
{
using kyosu::sub;
using e_t = float;
using we_t = eve::wide<float, eve::fixed<2>>;
using wc_t = eve::wide<kyosu::complex_t<float>, eve::fixed<2>>;
using wq_t = eve::wide<kyosu::quaternion_t<float>, eve::fixed<2>>;
std::cout << "Real: " << "\n";
e_t e0(1);
e_t e1(2);
std::cout << e0 << ", " << e1 << " -> " << kyosu::sub(e0, e1) << "\n";
std::cout << e0 << ", " << e0 << " -> " << sub(e0, e0) << "\n";
we_t we0(e0);
we_t we1(e1);
std::cout << we0 << ", " << we1 << " -> " << sub(we0, we1) << "\n";
std::cout << "Complex: " << "\n";
c_t c0(1, 5);
c_t c1(5, 9);
std::cout << c0 << ", " << c1 << " -> " << sub(c0, c1) << "\n";
std::cout << c0 << ", " << c0 << " -> " << sub(c0, c0) << "\n";
wc_t wc0(c0, c1);
wc_t wc1(c1, c1);
std::cout << wc0 << ", " << wc1 << " -> " << sub(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 << " -> " << sub(q0, q1) << "\n";
std::cout << q0 << ", " << q0 << " -> " << sub(q0, q0) << "\n";
std::cout << q0 << ", " << q0 << ", " << q1 << " -> " << sub(q0, q0, q1) << "\n";
wq_t wq0(q0, q1);
wq_t wq1(q1, q1);
std::cout << wq0 << ", " << wq1 << " -> " << sub(wq0, wq1) << "\n";
std::cout << "Mixed: " << "\n";
std::cout << kyosu::sub(c0, e0) << std::endl;
std::cout << kyosu::sub(c0, c0, c1) << std::endl;
std::cout << kyosu::sub(c0, e0, c1) << std::endl;
std::cout << kyosu::sub(c0, q1, e0) << std::endl;
std::cout << kyosu::sub(e0, q1, c1) << std::endl;
std::cout << kyosu::sub(c0, wq1) << std::endl;
std::cout << kyosu::sub(we0, q1) << std::endl;
std::cout << c0 << " == " << e0 << " == " << kyosu::sub[e0 > 32](c0, e0) << std::endl;
std::cout << c0 << " == " << e0 << " == " << kyosu::sub[e0 < 32](c0, e0) << std::endl;
kumi::tuple s{c0, c0, c1};
std::cout << "kyosu::sub( kumi::tuple s{c0, c0, c1}) == " << kyosu::sub(s) << std::endl;
return 0;
}
as_cayley_dickson_n_t< 2, T > complex_t
Type alias for complex numbers.
Definition complex.hpp:27
as_cayley_dickson_n_t< 4, T > quaternion_t
Type alias for quaternion numbers.
Definition quaternion.hpp:24