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

◆ sqrt

auto kyosu::sqrt = eve::functor<sqrt_t>
inlineconstexpr

Computes a square root value.

Header file

#include <kyosu/functions.hpp>

Callable Signatures

namespace kyosu
{
// regular call
constexpr auto sqrt(auto z) noexcept; //1
template<eve::value K> constexpr auto sqrt(auto z, K k) noexcept; //2
// semantic modifyers
template<eve::value K> constexpr auto sqrt[principal](\*any previus overload) noexcept; //3
template<concepts::real T> constexpr auto sqrt[real_only](T z) noexcept; //1
}
constexpr auto k
Computes the complex number k i.e. quaternion(0, 0, 0, 1) in the chosen type.
Definition k.hpp:74
constexpr auto sqrt
Computes a square root value.
Definition sqrt.hpp:99
Main KYOSU namespace.
Definition cinf.hpp:13

Parameters

  • z: Value to for which square root is computed.
  • k: index of the square root taken modulo 1.

Return value

  1. With one parameter returns the principal square root of z which has the same imaginary part sign as z.
    • A real typed input z is treated as if complex(z) was entered, unless the option real_only is used in which case the parameter must be a floating_value and the result will the same as a call to eve::rsqrt
    • for complex input, returns elementwise the square root of z, in the range of the right half-plane, including the imaginary axis ( \([0, +\infty]\) along the real axis and \([-\infty, +\infty]\) along the imaginary axis.)
    • The function is continuous onto the branch cut taking into account the sign of imaginary part
    • kyosu::sqrt(kyosu::conj(z)) == kyosu::conj(kyosu::sqrt(z))
    • If z is \(\pm0\), the result is \(+0\)
    • If z is \(x+i \infty\), the result is \(\infty+i \infty\) even if x is \(NaN\)
    • If z is \(x,NaN\), the result is \(NaN,NaN\) (unless x is \(\pm\infty\))
    • If z is \(-\infty+i y\), the result is \(+0+i \infty\) for finite positive y
    • If z is \(+\infty+i y\), the result is \(+\infty+i 0\) for finite positive y
    • If z is \(-\infty+i NaN\), the result is \(NaN \pm i \infty\) (sign of imaginary part unspecified)
    • If z is \(+\infty+i NaN\), the result is \(+\infty+i NaN\)
    • If z is \(NaN+i y\), the result is \(NaN+i NaN\)
    • If z is \(NaN+i NaN\), the result is \(NaN+i NaN\)
  2. Returns the kth sqrt root of z, k is taken modulo 1; 0 is identical to 1. 1 gives the opposite root.

External references

Example

#include <eve/wide.hpp>
#include <iostream>
#include <kyosu/kyosu.hpp>
int main()
{
using kyosu::sqrt;
std::cout << "Real: ";
std::cout << 72.9f << " -> " << sqrt(72.9f) << "\n";
std::cout << "Complex: ";
std::cout << kyosu::complex_t<float>(3.5f, -2.9f) << " -> " << sqrt(kyosu::complex_t<float>(3.5f, -2.9f)) << "\n";
std::cout << "Quaternion: ";
std::cout << kyosu::quaternion_t<double>(1., 2., 3., 4.) << " -> "
<< sqrt(kyosu::quaternion_t<double>(1., 2., 3., 4.)) << "\n";
std::cout << "SIMD: ";
using wc_t = eve::wide<kyosu::complex_t<double>, eve::fixed<2>>;
std::cout << wc_t(kyosu::complex_t<double>(1.3, -3.7)) << " -> " << sqrt(wc_t(kyosu::complex_t<double>(1.3, -3.7)))
<< "\n";
using e_t = float;
using z_t = kyosu::complex_t<e_t>;
using k_t = eve::wide<e_t, eve::fixed<2>>;
z_t z{e_t(1.0), e_t(2.0)};
k_t k{0, 1};
e_t e(1.0);
std::cout << "z " << z << std::endl;
std::cout << "k " << k << std::endl;
std::cout << "sqrt(z) " << sqrt(z) << std::endl;
std::cout << "sqrt(z, k) " << sqrt(z, k) << std::endl;
std::cout << "sqrt(e) " << sqrt(e) << std::endl;
std::cout << "sqrt[kyosu::real_only](e) " << sqrt[kyosu::real_only](e) << std::endl;
std::cout << "sqrt(-e)" << sqrt(-e) << std::endl;
std::cout << "sqrt[kyosu::real_only](-e) " << sqrt[kyosu::real_only](-e) << std::endl;
std::cout << "sqrt(e, k) " << sqrt(e, k) << std::endl;
std::cout << "sqrt[kyosu::real_only](e, k) " << sqrt[kyosu::real_only](e, k) << std::endl;
std::cout << "sqrt[kyosu::real_only](-e, k) " << sqrt[kyosu::real_only](-e, k) << std::endl;
std::cout << "sqrt[kyosu::real_only](z, k) " << sqrt[kyosu::real_only](z, k) << 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