Vc  1.4.1
SIMD Vector Classes for C++
Math

Detailed Description

Functions that implement math functions. Take care that some of the implementations will return results with less precision than what the FPU calculates.

Functions

Vc::Vector< T > sqrt (const Vc::Vector< T > &v)
 Returns the square root of v.
 
Vc::Vector< T > rsqrt (const Vc::Vector< T > &v)
 Returns the reciprocal square root of v.
 
Vc::Vector< T > reciprocal (const Vc::Vector< T > &v)
 Returns the reciprocal of v.
 
Vc::Vector< T > abs (const Vc::Vector< T > &v)
 Returns the absolute value of v.
 
Vc::Vector< T > round (const Vc::Vector< T > &v)
 Returns the closest integer to v; 0.5 is rounded to even.
 
Vc::Vector< T > log (const Vc::Vector< T > &v)
 
Vc::Vector< T > log2 (const Vc::Vector< T > &v)
 
Vc::Vector< T > log10 (const Vc::Vector< T > &v)
 
Vc::Vector< T > exp (const Vc::Vector< T > &v)
 
Vc::Vector< T > min (const Vc::Vector< T > &x, const Vc::Vector< T > &y)
 
Vc::Vector< T > max (const Vc::Vector< T > &x, const Vc::Vector< T > &y)
 
Vc::Vector< T > frexp (const Vc::Vector< T > &x, Vc::SimdArray< int, size()> *e)
 Convert floating-point number to fractional and integral components. More...
 
Vc::Vector< T > ldexp (Vc::Vector< T > x, Vc::SimdArray< int, size()> e)
 Multiply floating-point number by integral power of 2. More...
 
Vc::Mask< T > isfinite (const Vc::Vector< T > &x)
 
Vc::Mask< T > isnan (const Vc::Vector< T > &x)
 
Vc::Vector< T > fma (Vc::Vector< T > a, Vc::Vector< T > b, Vc::Vector< T > c)
 Multiplies a with b and then adds c, without rounding between the multiplication and the addition. More...
 
template<typename T , typename Abi >
Vector< T, detail::not_fixed_size_abi< Abi > > sin (const Vector< T, Abi > &x)
 Returns the sine of all input values in x. More...
 
template<typename T , typename Abi >
Vector< T, detail::not_fixed_size_abi< Abi > > cos (const Vector< T, Abi > &x)
 Returns the cosine of all input values in x. More...
 
template<typename T , typename Abi >
Vector< T, detail::not_fixed_size_abi< Abi > > asin (const Vector< T, Abi > &x)
 Returns the arcsine of all input values in x. More...
 
template<typename T , typename Abi >
Vector< T, detail::not_fixed_size_abi< Abi > > atan (const Vector< T, Abi > &x)
 Returns the arctangent of all input values in x. More...
 
template<typename T , typename Abi >
Vector< T, detail::not_fixed_size_abi< Abi > > atan2 (const Vector< T, Abi > &y, const Vector< T, Abi > &x)
 Returns the arctangent of all input values in x and y. More...
 
template<typename T , typename Abi >
void sincos (const Vector< T, Abi > &x, Vector< T, detail::not_fixed_size_abi< Abi >> *sin, Vector< T, Abi > *cos)
 
template<typename T , typename Abi , typename = enable_if<std::is_floating_point<T>::value && !detail::is_fixed_size_abi<Abi>::value>>
Vector< T, Abi > copysign (Vector< T, Abi > magnitude, Vector< T, Abi > sign)
 Copies the sign(s) of sign to the value(s) in magnitude and returns the resulting vector. More...
 
template<typename T , typename Abi , typename = enable_if<std::is_floating_point<T>::value && !detail::is_fixed_size_abi<Abi>::value>>
Vector< T, Abi > exponent (Vector< T, Abi > x)
 Extracts the exponent of each floating-point vector component. More...
 
template<typename T , typename Abi >
Vector< T, detail::not_fixed_size_abi< Abi > >::MaskType isnegative (Vector< T, Abi > x)
 Returns for each vector component whether it stores a negative value. More...
 

Function Documentation

◆ log()

Vc::Vector<T> Vc::log ( const Vc::Vector< T > &  v)
Parameters
vThe values to apply the logarithm on.
Returns
the natural logarithm of v.
Note
The single-precision implementation has an error of max. 1 ulp (mean 0.020 ulp) in the range ]0, 1000] (including denormals).
The double-precision implementation has an error of max. 1 ulp (mean 0.020 ulp) in the range ]0, 1000] (including denormals).

◆ log2()

Vc::Vector<T> Vc::log2 ( const Vc::Vector< T > &  v)
Parameters
vThe values to apply the logarithm on.
Returns
the base-2 logarithm of v.
Note
The single-precision implementation has an error of max. 1 ulp (mean 0.016 ulp) in the range ]0, 1000] (including denormals).
The double-precision implementation has an error of max. 1 ulp (mean 0.016 ulp) in the range ]0, 1000] (including denormals).

◆ log10()

Vc::Vector<T> Vc::log10 ( const Vc::Vector< T > &  v)
Parameters
vThe values to apply the logarithm on.
Returns
the base-10 logarithm of v.
Note
The single-precision implementation has an error of max. 2 ulp (mean 0.31 ulp) in the range ]0, 1000] (including denormals).
The double-precision implementation has an error of max. 2 ulp (mean 0.26 ulp) in the range ]0, 1000] (including denormals).

◆ exp()

Vc::Vector<T> Vc::exp ( const Vc::Vector< T > &  v)
Parameters
vThe values to apply the exponential function on.
Returns
the exponential of v.

◆ min()

Vc::Vector<T> Vc::min ( const Vc::Vector< T > &  x,
const Vc::Vector< T > &  y 
)
Parameters
x\(\mathcal{W}_\mathtt{T}\) values to compare component-wise against y.
y\(\mathcal{W}_\mathtt{T}\) values to compare component-wise against x.
Returns
the minimum of x and y.

Referenced by SimdArray< T, N >::sorted().

◆ max()

Vc::Vector<T> Vc::max ( const Vc::Vector< T > &  x,
const Vc::Vector< T > &  y 
)
Parameters
x\(\mathcal{W}_\mathtt{T}\) values to compare component-wise against y.
y\(\mathcal{W}_\mathtt{T}\) values to compare component-wise against x.
Returns
the maximum of x and y.

Referenced by SimdArray< T, N >::sorted().

◆ frexp()

Vc::Vector<T> Vc::frexp ( const Vc::Vector< T > &  x,
Vc::SimdArray< int, size()> *  e 
)

Convert floating-point number to fractional and integral components.

Parameters
xvalue to be split into normalized fraction and exponent
ethe exponent to base 2 of x
Returns
the normalized fraction. If x is non-zero, the return value is x times a power of two, and its absolute value is always in the range [0.5,1).
If x is zero, then the normalized fraction is zero and zero is stored in e.
If x is a NaN, a NaN is returned, and the value of *e is unspecified.
If x is positive infinity (negative infinity), positive infinity (nega‐ tive infinity) is returned, and the value of *e is unspecified.

◆ ldexp()

Vc::Vector<T> Vc::ldexp ( Vc::Vector< T >  x,
Vc::SimdArray< int, size()>  e 
)

Multiply floating-point number by integral power of 2.

Parameters
xvalue to be multiplied by 2 ^ e
eexponent
Returns
x * 2 ^ e

◆ isfinite()

Vc::Mask<T> Vc::isfinite ( const Vc::Vector< T > &  x)
Parameters
xThe \(\mathcal{W}_\mathtt{T}\) values to check for finite values.
Returns
a mask that tells whether the values in the vector are finite (i.e. not NaN or +/-inf).

◆ isnan()

Vc::Mask<T> Vc::isnan ( const Vc::Vector< T > &  x)
Parameters
xThe \(\mathcal{W}_\mathtt{T}\) values to check for NaN values.
Returns
a mask that tells whether the values in the vector are NaN.

◆ fma()

Vc::Vector<T> Vc::fma ( Vc::Vector< T >  a,
Vc::Vector< T >  b,
Vc::Vector< T >  c 
)

Multiplies a with b and then adds c, without rounding between the multiplication and the addition.

Parameters
aFirst multiplication factor.
bSecond multiplication factor.
cSummand that will be added after multiplication.
Returns
The \(\mathcal{W}_\mathtt{T}\) values of a * b + c with higher precision due to no rounding between multiplication and addition.
Note
This operation may have explicit hardware support, in which case it is normally faster to use the FMA instead of separate multiply and add instructions.
If the target hardware does not have FMA support this function will be considerably slower than a normal a * b + c. This is due to the increased precision fusedMultiplyAdd provides.
The compiler normally detects opportunities for using the hardware FMA instructions from normal multiplication and addition/subtraction operators. Use this function only if you require the additional precision.

◆ sin()

Vector<T, detail::not_fixed_size_abi<Abi> > Vc::sin ( const Vector< T, Abi > &  x)
inline

Returns the sine of all input values in x.

Parameters
xThe values to apply the sine function on.
Returns
the sine of x.
Note
The single-precision implementation has a precision of max. 2 ulp (mean 0.17 ulp) in the range [-8192, 8192]. (testSin< float_v> with a maximal distance of 2 to the reference (mean: 0.310741))
The double-precision implementation has a precision of max. 3 ulp (mean 1040 ulp) in the range [-8192, 8192]. (testSin<double_v> with a maximal distance of 1 to the reference (mean: 0.170621))
The precision and execution latency depends on:
  • Abi (e.g. Scalar uses the <cmath> implementation
  • whether Vc_HAVE_LIBMVEC is defined
  • for the <cmath> fallback, the implementations differ (e.g. MacOS vs. Linux vs. Windows; fpmath=sse vs. fpmath=387)
Vc versions before 1.4 had different precision.

Definition at line 134 of file trigonometric.h.

Referenced by Vc::sincos().

◆ cos()

Vector<T, detail::not_fixed_size_abi<Abi> > Vc::cos ( const Vector< T, Abi > &  x)
inline

Returns the cosine of all input values in x.

Parameters
xThe values to apply the cosine function on.
Returns
the cosine of x.
Note
The single-precision implementation has a precision of max. 2 ulp (mean 0.18 ulp) in the range [-8192, 8192].
The double-precision implementation has a precision of max. 3 ulp (mean 1160 ulp) in the range [-8192, 8192].
Vc versions before 1.4 had different precision.

Definition at line 151 of file trigonometric.h.

◆ asin()

Vector<T, detail::not_fixed_size_abi<Abi> > Vc::asin ( const Vector< T, Abi > &  x)
inline

Returns the arcsine of all input values in x.

Parameters
xThe values to apply the arcsine function on.
Returns
the arcsine of x.
Note
The single-precision implementation has an error of max. 2 ulp (mean 0.3 ulp).
The double-precision implementation has an error of max. 36 ulp (mean 0.4 ulp).

Definition at line 168 of file trigonometric.h.

◆ atan()

Vector<T, detail::not_fixed_size_abi<Abi> > Vc::atan ( const Vector< T, Abi > &  x)
inline

Returns the arctangent of all input values in x.

Parameters
xThe values to apply the arctangent function on.
Returns
the arctangent of x.
Note
The single-precision implementation has an error of max. 3 ulp (mean 0.4 ulp) in the range [-8192, 8192].
The double-precision implementation has an error of max. 2 ulp (mean 0.1 ulp) in the range [-8192, 8192].

Definition at line 183 of file trigonometric.h.

◆ atan2()

Vector<T, detail::not_fixed_size_abi<Abi> > Vc::atan2 ( const Vector< T, Abi > &  y,
const Vector< T, Abi > &  x 
)
inline

Returns the arctangent of all input values in x and y.

Calculates the angle given the lengths of the opposite and adjacent legs in a right triangle.

Parameters
yThe opposite leg.
xThe adjacent leg.
Returns
the arctangent of y / x.

Definition at line 199 of file trigonometric.h.

◆ sincos()

void Vc::sincos ( const Vector< T, Abi > &  x,
Vector< T, detail::not_fixed_size_abi< Abi >> *  sin,
Vector< T, Abi > *  cos 
)
inline
Parameters
xInput value to both sine and cosine.
sinA non-null pointer to a potentially uninitialized object of type Vector. When sincos returns, *sin contains the result of sin(x).
cosA non-null pointer to a potentially uninitialized object of type Vector. When sincos returns, *cos contains the result of cos(x).
See also
sin, cos

Definition at line 217 of file trigonometric.h.

◆ copysign()

Vector<T, Abi> Vc::copysign ( Vector< T, Abi >  magnitude,
Vector< T, Abi >  sign 
)
inline

Copies the sign(s) of sign to the value(s) in magnitude and returns the resulting vector.

Parameters
magnitudeThis vector's magnitude will be used in the return vector.
signThis vector's sign bit will be used in the return vector.
Returns
a value where the sign of the value equals the sign of sign. I.e. sign(copysign(v, r)) == sign(r).

Referenced by Vector< T, Abi >::scatter().

◆ exponent()

Vector<T, Abi> Vc::exponent ( Vector< T, Abi >  x)
inline

Extracts the exponent of each floating-point vector component.

Parameters
xThe vector of values to check for the sign.
Returns
the exponent to base 2.

This function provides efficient access to the exponent of the floating point number. The returned value is a fast approximation to the logarithm of base 2. The absolute error of that approximation is between [0, 1[.

Examples:

 value | exponent | log2
=======|==========|=======
   1.0 |        0 | 0
   2.0 |        1 | 1
   3.0 |        1 | 1.585
   3.9 |        1 | 1.963
   4.0 |        2 | 2
   4.1 |        2 | 2.036
Warning
This function assumes a positive value (non-zero). If the value is negative the sign bit will modify the returned value. An input value of zero will return the bias of the floating-point representation. If you compile with Vc runtime checks, the function will assert values greater than or equal to zero.

You may use abs to apply this function to negative values:

◆ isnegative()

Vector<T, detail::not_fixed_size_abi<Abi> >::MaskType Vc::isnegative ( Vector< T, Abi >  x)
inline

Returns for each vector component whether it stores a negative value.

Parameters
xThe vector of values to check for the sign.
Returns
a mask which is true only in those components that are negative in x.

Definition at line 106 of file vector.h.