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>
inline batch<T, A> abs(batch<T, A> const &x) noexcept

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

Parameters:

x – batch of integer or floating point values.

Returns:

the absolute values of x.

template<class T, class A>
inline batch<T, A> cbrt(batch<T, A> const &x) noexcept

Computes the cubic root of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the cubic root of x.

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

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

Parameters:
  • x – batch of scalar values.

  • lo – batch of scalar values.

  • hi – batch of scalar values.

Returns:

the result of the clipping.

template<class T, class A>
inline batch<T, A> exp(batch<T, A> const &x) noexcept

Computes the natural exponential of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the natural exponential of x.

template<class T, class A>
inline batch<T, A> exp10(batch<T, A> const &x) noexcept

Computes the base 10 exponential of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the base 10 exponential of x.

template<class T, class A>
inline batch<T, A> exp2(batch<T, A> const &x) noexcept

Computes the base 2 exponential of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the base 2 exponential of x.

template<class T, class A>
inline batch<T, A> expm1(batch<T, A> const &x) noexcept

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

Parameters:

x – batch of floating point values.

Returns:

the natural exponential of x, minus one.

template<class T, class A>
inline batch<T, A> fabs(batch<T, A> const &x) noexcept

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

Parameters:

x – batch floating point values.

Returns:

the absolute values of x.

template<class T, class A>
inline batch<T, A> fdim(batch<T, A> const &x, batch<T, A> const &y) noexcept

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

Parameters:
  • x – batch of floating point values.

  • y – batch of floating point values.

Returns:

the positive difference.

template<class T, class A>
inline batch<T, A> fmax(batch<T, A> const &x, batch<T, A> const &y) noexcept

Computes the larger values of the batches x and y.

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

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

Returns:

a batch of the larger values.

template<class T, class A>
inline batch<T, A> fmin(batch<T, A> const &x, batch<T, A> const &y) noexcept

Computes the smaller values of the batches x and y.

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

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

Returns:

a batch of the smaller values.

template<class T, class A>
inline batch<T, A> fmod(batch<T, A> const &x, batch<T, A> const &y) noexcept

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

Parameters:
  • x – batch involved in the modulo.

  • y – batch involved in the modulo.

Returns:

the result of the modulo.

template<class T, class A>
inline batch<T, A> hypot(batch<T, A> const &x, batch<T, A> const &y) noexcept

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

Parameters:
  • x – batch of floating point values.

  • y – batch of floating point values.

Returns:

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

template<class T, class A>
inline batch<T, A> log(batch<T, A> const &x) noexcept

Computes the natural logarithm of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the natural logarithm of x.

template<class T, class A>
inline batch<T, A> log2(batch<T, A> const &x) noexcept

Computes the base 2 logarithm of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the base 2 logarithm of x.

template<class T, class A>
inline batch<T, A> log10(batch<T, A> const &x) noexcept

Computes the base 10 logarithm of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the base 10 logarithm of x.

template<class T, class A>
inline batch<T, A> log1p(batch<T, A> const &x) noexcept

Computes the natural logarithm of one plus the batch x.

Parameters:

x – batch of floating point values.

Returns:

the natural logarithm of one plus x.

template<class T, class A>
inline batch<T, A> max(batch<T, A> const &x, batch<T, A> const &y) noexcept

Computes the larger values of the batches x and y.

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

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

Returns:

a batch of the larger values.

template<class T, class A>
inline batch<T, A> min(batch<T, A> const &x, batch<T, A> const &y) noexcept

Computes the smaller values of the batches x and y.

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

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

Returns:

a batch of the smaller values.

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

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

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

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

Returns:

r exp(i * theta).

template<class T, class A>
inline batch<T, A> pow(batch<T, A> const &x, batch<T, A> const &y) noexcept

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

Parameters:
  • x – batch of floating point values.

  • y – batch of floating point values.

Returns:

x raised to the power y.

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

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

Parameters:
  • x – batch of integral values.

  • y – batch of integral values.

Returns:

x raised to the power y.

template<class T, class A>
inline batch<T, A> remainder(batch<T, A> const &x, batch<T, A> const &y) noexcept

Computes the remainder of dividing x by y.

Parameters:
  • x – batch of scalar values

  • y – batch of scalar values

Returns:

the result of the addition.

template<class T, class A>
inline batch<T, A> rsqrt(batch<T, A> const &x) noexcept

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.

Parameters:

x – batch of floating point values.

Returns:

the inverse square root of x.

template<class T, class A>
inline batch<T, A> sqrt(batch<T, A> const &x) noexcept

Computes the square root of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the square root of x.

template<class T, class A>
inline batch<T, A> acos(batch<T, A> const &x) noexcept

Computes the arc cosine of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the arc cosine of x.

template<class T, class A>
inline batch<T, A> acosh(batch<T, A> const &x) noexcept

Computes the inverse hyperbolic cosine of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the inverse hyperbolic cosine of x.

template<class T, class A>
inline batch<T, A> asin(batch<T, A> const &x) noexcept

Computes the arc sine of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the arc sine of x.

template<class T, class A>
inline batch<T, A> asinh(batch<T, A> const &x) noexcept

Computes the inverse hyperbolic sine of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the inverse hyperbolic sine of x.

template<class T, class A>
inline batch<T, A> atan(batch<T, A> const &x) noexcept

Computes the arc tangent of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the arc tangent of x.

template<class T, class A>
inline batch<T, A> atan2(batch<T, A> const &x, batch<T, A> const &y) noexcept

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

Parameters:
  • x – batch of floating point values.

  • y – batch of floating point values.

Returns:

the arc tangent of x/y.

template<class T, class A>
inline batch<T, A> atanh(batch<T, A> const &x) noexcept

Computes the inverse hyperbolic tangent of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the inverse hyperbolic tangent of x.

template<class T, class A>
inline batch<T, A> cos(batch<T, A> const &x) noexcept

Computes the cosine of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the cosine of x.

template<class T, class A>
inline batch<T, A> cosh(batch<T, A> const &x) noexcept

computes the hyperbolic cosine of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the hyperbolic cosine of x.

template<class T, class A>
inline batch<T, A> sin(batch<T, A> const &x) noexcept

Computes the sine of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the sine of x.

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

Computes the sine and the cosine of the batch x.

This method is faster than calling sine and cosine independently.

Parameters:

x – batch of floating point values.

Returns:

a pair containing the sine then the cosine of batch x

template<class T, class A>
inline batch<T, A> sinh(batch<T, A> const &x) noexcept

Computes the hyperbolic sine of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the hyperbolic sine of x.

template<class T, class A>
inline batch<T, A> tan(batch<T, A> const &x) noexcept

Computes the tangent of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the tangent of x.

template<class T, class A>
inline batch<T, A> tanh(batch<T, A> const &x) noexcept

Computes the hyperbolic tangent of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the hyperbolic tangent of x.

template<class T, class A>
inline batch<T, A> ceil(batch<T, A> const &x) noexcept

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

Parameters:

x – batch of floating point values.

Returns:

the batch of smallest integer values not less than x.

template<class T, class A>
inline batch<T, A> floor(batch<T, A> const &x) noexcept

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

Parameters:

x – batch of floating point values.

Returns:

the batch of largest integer values not greater than x.

template<class T, class A>
inline batch<T, A> nearbyint(batch<T, A> const &x) noexcept

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

Parameters:

x – batch of floating point values.

Returns:

the batch of nearest integer values.

template<class T, class A>
inline batch<as_integer_t<T>, A> nearbyint_as_int(batch<T, A> const &x) noexcept

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

Warning

For very large values the conversion to int silently overflows.

Parameters:

x – batch of floating point values.

Returns:

the batch of nearest integer values.

template<class T, class A>
inline batch<T, A> rint(batch<T, A> const &x) noexcept

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

Parameters:

x – batch of floating point values.

Returns:

the batch of rounded values.

template<class T, class A>
inline batch<T, A> round(batch<T, A> const &x) noexcept

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.

Parameters:

x – batch of flaoting point values.

Returns:

the batch of nearest integer values.

template<class T, class A>
inline batch<T, A> trunc(batch<T, A> const &x) noexcept

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

Parameters:

x – batch of floating point values.

Returns:

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

template<class T, class A>
inline batch<T, A> erf(batch<T, A> const &x) noexcept

Computes the error function of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the error function of x.

template<class T, class A>
inline batch<T, A> erfc(batch<T, A> const &x) noexcept

Computes the complementary error function of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the error function of x.

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

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

Parameters:
  • x – batch of floating point values.

  • y – batch of integer values.

Returns:

a batch of floating point values.

template<class T, class A>
inline batch<T, A> lgamma(batch<T, A> const &x) noexcept

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

Parameters:

x – batch of floating point values.

Returns:

the natural logarithm of the gamma function of x.

template<class T, class A>
inline batch<T, A> nextafter(batch<T, A> const &x, batch<T, A> const &y) noexcept

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

Parameters:
  • x – batch of floating point values.

  • y – batch of floating point values.

Returns:

x raised to the power y.

template<class T, class A>
inline batch<T, A> tgamma(batch<T, A> const &x) noexcept

Computes the gamma function of the batch x.

Parameters:

x – batch of floating point values.

Returns:

the gamma function of x.