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

◆ pow

kyosu::pow = {}
inlineconstexpr

Computes the computing the pow operation \(x^y\).

Defined in Header

#include <kyosu/functions.hpp>

Callable Signatures

namespace kyosu
{
constexpr auto pow(auto z0, auto z1) noexcept; \\123
constexpr auto pow(auto z0, eve::integral_value n) noexcept; \\4
}
constexpr tags::callable_pow pow
Computes the computing the pow operation .
Definition: pow.hpp:113
Main KYOSU namespace.
Definition: types.hpp:14

Parameters

  • z0, z1: Values to process.

Return value

  1. if both parameters are floating the call will act as if they were converted to complex before call
  2. if both parameters are floating or complex. The ieee specification are taken:
    In particular we have (IEC 60559):
    • pow(+0, y), where y is a negative odd integer, returns \(+\infty\)
    • pow(-0, y), where y is a negative odd integer, returns \(-\infty\)
    • pow( \(\pm0\), y), where y is negative, finite, and is an even integer or a non-integer, returns \(+\infty\)
    • pow( \(\pm0\), \(-\infty\)) returns \(+\infty\)
    • pow(+0, y), where y is a positive odd integer, returns +0
    • pow(-0, y), where y is a positive odd integer, returns -0
    • pow( \(\pm0\), y), where y is positive non-integer or a positive even integer, returns +0
    • pow(-1, \(\pm\infty\)) returns 1
    • pow(+1, y) returns 1 for any y, even when y is NaN
    • pow(x, \(\pm0\)) returns 1 for any x, even when x is NaN
    • pow(x, y) returns NaN if x is finite and less than 0 and y is finite and non-integer.
    • pow(x, \(-\infty\)) returns \(+\infty\) for any |x|<1
    • pow(x, \(-\infty\)) returns +0 for any |x|>1
    • pow(x, \(+\infty\)) returns +0 for any |x|<1
    • pow(x, \(+\infty\)) returns \(+\infty\) for any |x|>1
    • pow( \(-\infty\), y) returns -0 if y is a negative odd integer
    • pow( \(-\infty\), y) returns +0 if y is a negative non-integer or even integer
    • pow( \(-\infty\), y) returns \(-\infty\) if y is a positive odd integer
    • pow( \(-\infty\), y) returns \(+\infty\) if y is a positive non-integer or even integer
    • pow( \(+\infty\), y) returns +0 for any y less than 0
    • pow( \(+\infty\), y) returns \(+\infty\) for any y greater than 0
    • except where specified above, if any argument is NaN, NaN is returned
  3. if any parameter as a dimensionnality greater than 2, the call is semantically equivalent to kyosu::exp(z1*eve::log(z0))
  4. pow can accept an integral typed second parameter, in this case it is the russian peasant algorithm that is used.

Example

#include <kyosu/kyosu.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
using kyosu::pow;
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 << " -> " << 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;
}
as_cayley_dickson_n_t< 4, T > quaternion_t
Type alias for quaternion numbers.
Definition: quaternion.hpp:27
as_cayley_dickson_n_t< 2, T > complex_t
Type alias for complex numbers.
Definition: complex.hpp:27