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

◆ sqrt

kyosu::sqrt = {}
inlineconstexpr

Computes a square root value.

Defined in Header

#include <kyosu/functions.hpp>

Callable Signatures

namespace kyosu
{
template<eve::floating_ordered_value T> constexpr T sqrt(T z) noexcept; //1
template<kyosu::concepts::complex T> constexpr T sqrt(T z) noexcept; //2
template<kyosu::concepts::cayley_dickson T> constexpr T sqrt(T z) noexcept; //3
}
constexpr tags::callable_sqrt sqrt
Computes a square root value.
Definition: sqrt.hpp:98
Main KYOSU namespace.
Definition: types.hpp:14

Parameters

  • z: Value to for which square root is computed.

Return value

  1. a real typed input z is treated as if kyosu::complex(z) was entered.
  2. Returns the 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
    • eve::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\)
  1. Returns a square root of z.

Example

#include <kyosu/kyosu.hpp>
#include <eve/wide.hpp>
#include <iostream>
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";
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