◆ nthroot()

Value boost::simd::nthroot ( Value const &  x,
IntegerValue const &  n 
)

This function object returns the nth root of its first argument: \(\sqrt[n]{x}\).

  • n must be of integer type
  • if n is even and x negative the result is Nan
  • if x is null the result is Zero
  • if x is one the result is One
Header <boost/simd/function/nthroot.hpp>
Note:
nthroot is slower than pow(x, rec(tofloat(n))) because it takes care of some limits issues that pow ignores.

See if it suits you better or use raw_ decorator for intermediate solution.

Decorators
  • raw_ provides increased speed but is undefined for limitings values
See also
pow, rec, sqrt, cbrt
Example:
#include <boost/simd/exponential.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using iT = std::int32_t;
using pack_it = bs::pack<iT, 4>;
using pack_ft = bs::pack<float, 4>;
int main() {
pack_ft pf = {1, 2, -1, 8};
pack_it qi = {1, 2, 3, 3};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qi = " << qi << '\n'
<< "-> bs::nthroot(pf, qi) = " << bs::nthroot(pf, qi) << '\n';
float xf = -8;
iT yi = 3;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yi = " << yi << '\n'
<< "-> bs::nthroot(xf, yi) = " << bs::nthroot(xf, yi) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, 2, -1, 8)
<- qi = (1, 2, 3, 3)
-> bs::nthroot(pf, qi) = (1, 1.41421, -1, 2)
---- scalar
<- xf = -8
<- yi = 3
-> bs::nthroot(xf, yi) = -2