Mathematical functions
Basic functions:
absolute value |
|
absolute value of floating point values |
|
remainder of the floating point division operation |
|
signed remainder of the division operation |
|
smaller of two batches |
|
larger of two batches |
|
smaller of two batches of floating point values |
|
larger of two batches of floating point values |
|
positive difference |
|
clipping operation |
Exponential functions:
natural exponential function |
|
base 2 exponential function |
|
base 10 exponential function |
|
natural exponential function, minus one |
|
natural logarithm function |
|
base 2 logarithm function |
|
base 10 logarithm function |
|
natural logarithm of one plus function |
Power functions:
power function |
|
reciprocal square root function |
|
square root function |
|
cubic root function |
|
hypotenuse function |
Trigonometric functions:
sine function |
|
cosine function |
|
sine and cosine function |
|
tangent function |
|
arc sine function |
|
arc cosine function |
|
arc tangent function |
|
arc tangent function, determining quadrants |
Hyperbolic functions:
hyperbolic sine function |
|
hyperbolic cosine function |
|
hyperbolic tangent function |
|
inverse hyperbolic sine function |
|
inverse hyperbolic cosine function |
|
inverse hyperbolic tangent function |
Error functions:
error function |
|
complementary error function |
|
gamma function |
|
natural logarithm of the gamma function |
Nearint operations:
nearest integers not less |
|
nearest integers not greater |
|
nearest integers not greater in magnitude |
|
nearest integers, rounding away from zero |
|
nearest integers using current rounding mode |
|
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> avg(batch<T, A> const &x, batch<T, A> const &y) noexcept Computes the average of batches
x
andy
.- Parameters:
x – batch of T
y – batch of T
- Returns:
the average of elements between
x
andy
.
-
template<class T, class A>
inline batch<T, A> avgr(batch<T, A> const &x, batch<T, A> const &y) noexcept Computes the rounded average of batches
x
andy
.- Parameters:
x – batch of T
y – batch of T
- Returns:
the rounded average of elements between
x
andy
.
-
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 batcheslo
andhi
.- 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
andy
, 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
andy
.- 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
andy
.- 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 batchy
.- 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
, andy
.- 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
andy
.
-
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
andy
.- 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
andy
.- 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 angletheta
.- 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 powery
.- Parameters:
x – batch of floating point values.
y – batch of floating point values.
- Returns:
x
raised to the powery
.
-
template<class T, class A>
inline batch<std::complex<T>, A> pow(batch<std::complex<T>, A> const &x, batch<T, A> const &y) noexcept Computes the value of the batch
x
raised to the powery
.- Parameters:
x – batch of complex floating point values.
y – batch of floating point values.
- Returns:
x
raised to the powery
.
-
template<class T, class A>
inline batch<std::complex<T>, A> pow(batch<T, A> const &x, batch<std::complex<T>, A> const &y) noexcept Computes the value of the batch
x
raised to the powery
.- Parameters:
x – batch of complex floating point values.
y – batch of floating point values.
- Returns:
x
raised to the powery
.
-
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 powery
.- Parameters:
x – batch of integral values.
y – batch of integral values.
- Returns:
x
raised to the powery
.
-
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
byy
.- 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 powery
.- 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 powery
.