Mathematical functions

Basic functions:

abs()

absolute value

fabs()

absolute value of floating point values

fmod()

remainder of the floating point division operation

remainder()

signed remainder of the division operation

min()

smaller of two batches

max()

larger of two batches

fmin()

smaller of two batches of floating point values

fmax()

larger of two batches of floating point values

fdim()

positive difference

clip()

clipping operation

Exponential functions:

exp()

natural exponential function

exp2()

base 2 exponential function

exp10()

base 10 exponential function

expm1()

natural exponential function, minus one

log()

natural logarithm function

log2()

base 2 logarithm function

log10()

base 10 logarithm function

log1p()

natural logarithm of one plus function

Power functions:

pow()

power function

rsqrt()

reciprocal square root function

sqrt()

square root function

cbrt()

cubic root function

hypot()

hypotenuse function

Trigonometric functions:

sin()

sine function

cos()

cosine function

sincos()

sine and cosine function

tan()

tangent function

asin()

arc sine function

acos()

arc cosine function

atan()

arc tangent function

atan2()

arc tangent function, determining quadrants

Hyperbolic functions:

sinh()

hyperbolic sine function

cosh()

hyperbolic cosine function

tanh()

hyperbolic tangent function

asinh()

inverse hyperbolic sine function

acosh()

inverse hyperbolic cosine function

atanh()

inverse hyperbolic tangent function

Error functions:

erf()

error function

erfc()

complementary error function

tgamma()

gamma function

lgamma()

natural logarithm of the gamma function

Nearint operations:

ceil()

nearest integers not less

floor()

nearest integers not greater

trunc()

nearest integers not greater in magnitude

round()

nearest integers, rounding away from zero

nearbyint()

nearest integers using current rounding mode

rint()

nearest integers using current rounding mode


template <class T, class A>
batch<T, A> xsimd::abs(batch<T, A> const &x)

Computes the absolute values of each scalar in the batch x.

Return

the absolute values of x.

Parameters
  • x: batch of integer or floating point values.

template <class T, class A>
batch<T, A> xsimd::cbrt(batch<T, A> const &x)

Computes the cubic root of the batch x.

Return

the cubic root of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::clip(batch<T, A> const &x, batch<T, A> const &lo, batch<T, A> const &hi)

Clips the values of the batch x between those of the batches lo and hi.

Return

the result of the clipping.

Parameters
  • x: batch of scalar values.

  • lo: batch of scalar values.

  • hi: batch of scalar values.

template <class T, class A>
batch<T, A> xsimd::exp(batch<T, A> const &x)

Computes the natural exponential of the batch x.

Return

the natural exponential of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::exp10(batch<T, A> const &x)

Computes the base 10 exponential of the batch x.

Return

the base 10 exponential of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::exp2(batch<T, A> const &x)

Computes the base 2 exponential of the batch x.

Return

the base 2 exponential of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::expm1(batch<T, A> const &x)

Computes the natural exponential of the batch x, minus one.

Return

the natural exponential of x, minus one.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::fabs(batch<T, A> const &x)

Computes the absolute values of each scalar in the batch x.

Return

the absolute values of x.

Parameters
  • x: batch floating point values.

template <class T, class A>
batch<T, A> xsimd::fdim(batch<T, A> const &x, batch<T, A> const &y)

Computes the positive difference between x and y, that is, max(0, x-y).

Return

the positive difference.

Parameters
  • x: batch of floating point values.

  • y: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::fmax(batch<T, A> const &x, batch<T, A> const &y)

Computes the larger values of the batches x and y.

Return

a batch of the larger values.

Parameters
  • x: a batch of integer or floating point values.

  • y: a batch of integer or floating point values.

template <class T, class A>
batch<T, A> xsimd::fmin(batch<T, A> const &x, batch<T, A> const &y)

Computes the smaller values of the batches x and y.

Return

a batch of the smaller values.

Parameters
  • x: a batch of integer or floating point values.

  • y: a batch of integer or floating point values.

template <class T, class A>
batch<T, A> xsimd::fmod(batch<T, A> const &x, batch<T, A> const &y)

Computes the modulo of the batch x by the batch y.

Return

the result of the modulo.

Parameters
  • x: batch involved in the modulo.

  • y: batch involved in the modulo.

template <class T, class A>
batch<T, A> xsimd::hypot(batch<T, A> const &x, batch<T, A> const &y)

Computes the square root of the sum of the squares of the batches x, and y.

Return

the square root of the sum of the squares of x and y.

Parameters
  • x: batch of floating point values.

  • y: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::log(batch<T, A> const &x)

Computes the natural logarithm of the batch x.

Return

the natural logarithm of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::log2(batch<T, A> const &x)

Computes the base 2 logarithm of the batch x.

Return

the base 2 logarithm of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::log10(batch<T, A> const &x)

Computes the base 10 logarithm of the batch x.

Return

the base 10 logarithm of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::log1p(batch<T, A> const &x)

Computes the natural logarithm of one plus the batch x.

Return

the natural logarithm of one plus x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::max(batch<T, A> const &x, batch<T, A> const &y)

Computes the larger values of the batches x and y.

Return

a batch of the larger values.

Parameters
  • x: a batch of integer or floating point values.

  • y: a batch of integer or floating point values.

template <class T, class A>
batch<T, A> xsimd::min(batch<T, A> const &x, batch<T, A> const &y)

Computes the smaller values of the batches x and y.

Return

a batch of the smaller values.

Parameters
  • x: a batch of integer or floating point values.

  • y: a batch of integer or floating point values.

template <class T, class A>
complex_batch_type_t<batch<T, A>> xsimd::polar(batch<T, A> const &r, batch<T, A> const &theta = batch<T, A>{})

Returns a complex batch with magnitude r and phase angle theta.

Return

r exp(i * theta).

Parameters
  • r: The magnitude of the desired complex result.

  • theta: The phase angle of the desired complex result.

template <class T, class A>
batch<T, A> xsimd::pow(batch<T, A> const &x, batch<T, A> const &y)

Computes the value of the batch x raised to the power y.

Return

x raised to the power y.

Parameters
  • x: batch of floating point values.

  • y: batch of floating point values.

template <class T, class ITy, class A, class = typename std::enable_if<std::is_integral<ITy>::value, void>::type>
batch<T, A> xsimd::pow(batch<T, A> const &x, ITy y)

Computes the value of the batch x raised to the power y.

Return

x raised to the power y.

Parameters
  • x: batch of integral values.

  • y: batch of integral values.

template <class T, class A>
batch<T, A> xsimd::remainder(batch<T, A> const &x, batch<T, A> const &y)

Computes the remainder of dividing x by y.

Return

the result of the addition.

Parameters
  • x: batch of scalar values

  • y: batch of scalar values

template <class T, class A>
batch<T, A> xsimd::rsqrt(batch<T, A> const &x)

Computes an estimate of the inverse square root of the batch x.

Warning

Unlike most xsimd function, this does not return the same result as the equivalent scalar operation, trading accuracy for speed.

Return

the inverse square root of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::sqrt(batch<T, A> const &x)

Computes the square root of the batch x.

Return

the square root of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::acos(batch<T, A> const &x)

Computes the arc cosine of the batch x.

Return

the arc cosine of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::acosh(batch<T, A> const &x)

Computes the inverse hyperbolic cosine of the batch x.

Return

the inverse hyperbolic cosine of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::asin(batch<T, A> const &x)

Computes the arc sine of the batch x.

Return

the arc sine of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::asinh(batch<T, A> const &x)

Computes the inverse hyperbolic sine of the batch x.

Return

the inverse hyperbolic sine of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::atan(batch<T, A> const &x)

Computes the arc tangent of the batch x.

Return

the arc tangent of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::atan2(batch<T, A> const &x, batch<T, A> const &y)

Computes the arc tangent of the batch x/y, using the signs of the arguments to determine the correct quadrant.

Return

the arc tangent of x/y.

Parameters
  • x: batch of floating point values.

  • y: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::atanh(batch<T, A> const &x)

Computes the inverse hyperbolic tangent of the batch x.

Return

the inverse hyperbolic tangent of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::cos(batch<T, A> const &x)

Computes the cosine of the batch x.

Return

the cosine of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::cosh(batch<T, A> const &x)

computes the hyperbolic cosine of the batch x.

Return

the hyperbolic cosine of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::sin(batch<T, A> const &x)

Computes the sine of the batch x.

Return

the sine of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
std::pair<batch<T, A>, batch<T, A>> xsimd::sincos(batch<T, A> const &x)

Computes the sine and the cosine of the batch x.

This method is faster than calling sine and cosine independently.

Return

a pair containing the sine then the cosine of batch x

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::sinh(batch<T, A> const &x)

Computes the hyperbolic sine of the batch x.

Return

the hyperbolic sine of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::tan(batch<T, A> const &x)

Computes the tangent of the batch x.

Return

the tangent of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::tanh(batch<T, A> const &x)

Computes the hyperbolic tangent of the batch x.

Return

the hyperbolic tangent of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::ceil(batch<T, A> const &x)

Computes the batch of smallest integer values not less than scalars in x.

Return

the batch of smallest integer values not less than x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::floor(batch<T, A> const &x)

Computes the batch of largest integer values not greater than scalars in x.

Return

the batch of largest integer values not greater than x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::nearbyint(batch<T, A> const &x)

Rounds the scalars in x to integer values (in floating point format), using the current rounding mode.

Return

the batch of nearest integer values.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<as_integer_t<T>, A> xsimd::nearbyint_as_int(batch<T, A> const &x)

Rounds the scalars in x to integer values (in integer format) using the current rounding mode.

Return

the batch of nearest integer values.

Warning

For very large values the conversion to int silently overflows.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::rint(batch<T, A> const &x)

Rounds the scalars in x to integer values (in floating point format), using the current rounding mode.

Return

the batch of rounded values.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::round(batch<T, A> const &x)

Computes the batch of nearest integer values to scalars in x (in floating point format), rounding halfway cases away from zero, regardless of the current rounding mode.

Return

the batch of nearest integer values.

Parameters
  • x: batch of flaoting point values.

template <class T, class A>
batch<T, A> xsimd::trunc(batch<T, A> const &x)

Computes the batch of nearest integer values not greater in magnitude than scalars in x.

Return

the batch of nearest integer values not greater in magnitude than x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::erf(batch<T, A> const &x)

Computes the error function of the batch x.

Return

the error function of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::erfc(batch<T, A> const &x)

Computes the complementary error function of the batch x.

Return

the error function of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::ldexp(const batch<T, A> &x, const batch<as_integer_t<T>, A> &y)

Computes the multiplication of the floating point number x by 2 raised to the power y.

Return

a batch of floating point values.

Parameters
  • x: batch of floating point values.

  • y: batch of integer values.

template <class T, class A>
batch<T, A> xsimd::lgamma(batch<T, A> const &x)

Computes the natural logarithm of the gamma function of the batch x.

Return

the natural logarithm of the gamma function of x.

Parameters
  • x: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::nextafter(batch<T, A> const &x, batch<T, A> const &y)

Computes the next representable floating-point value following x in the direction of y.

Return

x raised to the power y.

Parameters
  • x: batch of floating point values.

  • y: batch of floating point values.

template <class T, class A>
batch<T, A> xsimd::tgamma(batch<T, A> const &x)

Computes the gamma function of the batch x.

Return

the gamma function of x.

Parameters
  • x: batch of floating point values.