E.V.E  0.1-beta

◆ nthroot

eve::nthroot = {}
inlineconstexpr

Callable object computing the nth root: \(x^{1/n}\).

Required header: #include <eve/function/nthroot.hpp>

Members Functions

Member Effect
operator() the nthroot operation
operator[] Construct a conditional version of current function object

template< floating_real_value T,integral_value U > auto operator()( T x, U n) const noexcept;

Parameters

x: floating real value.

n: integral_value. Actually n can be a flint.

Return value

Returns elementwise the value of \(x^{1/n}\). For negative x the value returned is a Nan as soon as n is not an odd integer.

The result type is of the compatibility type of the parameters.


auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::nthroot

Parameters

cond : conditional expression

Return value

A Callable object so that the expression nthroot[cond](x, ...) is equivalent to if_else(cond,nthroot(x, ...),x)


Supported decorators

  • eve::raw

    Required header: #include <eve/function/diff/nthroot.hpp>

    The expression raw(nthroot)(x,n) does not care about limiting values and gives less accurate values. for instance nthroot(64.0,3) is not exactly four but is 3.9999999999999991118 with a 0.5ulp error.

  • eve::diff, eve::diff_1st, eve::diff_nth

    Required header: #include <eve/function/diff/nthroot.hpp>

    The expression diff_1st(nthroot)(x,n) diff of \(f\), where \(f\) is the function \(x \rightarrow \ x^{1/n}\).

Example

See it live on Compiler Explorer

#include <eve/function/nthroot.hpp>
#include <eve/wide.hpp>
#include <eve/constant/inf.hpp>
#include <eve/constant/minf.hpp>
#include <eve/constant/nan.hpp>
#include <iostream>
#include <iomanip>
int main()
{
wide_ft pf = {2.0f, 64.0f, 4.0f, 2.0f, 2.0f,
wide_nt qn = {4, 3, 2, 1, 0, 4, 3, 2};
std::cout << "---- simd" << '\n'<< std::setprecision(20)
<< "<- pf = " << pf << '\n'
<< "<- qn = " << qn << '\n'
<< "-> nthroot(pf, qn) = " << eve::nthroot(pf, qn) << '\n'
<< "-> raw(nthroot)(pf, qn) = " << eve::raw(eve::nthroot)(pf, qn) << '\n';
double xf = 64.0f;
int n = 3;
std::cout << "---- scalar" << '\n' << std::setprecision(20)
<< "<- xf = " << xf << '\n'
<< "<- n = " << n << '\n'
<< "-> nthroot(xf, n) = " << eve::nthroot(xf, n) << '\n'
<< "-> raw(nthroot)(xf, n) = " << eve::raw(eve::nthroot)(xf, n) << '\n';
return 0;
}
constexpr callable_nan_ nan
Callable object computing the nan value.
Definition: nan.hpp:52
constexpr callable_minf_ minf
Callable object computing the negative infinity value.
Definition: minf.hpp:55
constexpr raw_type const raw
Higher-order Callable Object imbuing quick and dirty behaviour onto other Callable Objects.
Definition: raw.hpp:43
constexpr callable_nthroot_ nthroot
Callable object computing the nth root: .
Definition: nthroot.hpp:89
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65