vForce
Perform transcendental and trigonometric functions on vectors of any length.
Overview
The vForce library provides a range of trigonometric and transcendental functions that work over large collections of single- and double-precision values. The collections can be of any length, and vForce supplies vectorized functions for the current architecture.
The functions declared in the vForce library have the customary mathematical names, but with the prefix vv, for example, vvsqrtf(_:_:_:). Each mathematical function is available in two variants: one for single-precision data and one for double-precision data. The single-precision forms have the suffix f, whereas the double-precision forms have no suffix. For example, vvcosf(_:_:_:) is the single-precision cosine function, and vvcos(_:_:_:) is the double-precision variant.
All of the vForce library functions follow a common format:
The return type is
void.The first parameter points to an array to hold the results. The only exceptions are vvsincosf(_:_:_:_:) and vvsincos(_:_:_:_:), which have two result arrays that the first two parameters point to.
One or more parameters point to operand arrays that are the same length as the result array.
The last parameter is the array length.
Using vForce
The vForce library provides a high-performance alternative to for loops and map(_:) when applying operations on arrays of floating-point values.
For example, given an arbitrarily sized array, x, that contains single-precision values, the following code uses map(_:) to create a second array, y. On return, y contains the square root of each array element.
let n = 10_000
let x = (0..<n).map { _ in
Float.random(in: 1 ... 10_000)
}
let y = x.map {
return sqrt($0)
}The equivalent functionality implemented in vForce runs significantly faster:
let y = [Float](unsafeUninitializedCapacity: n) { buffer, initializedCount in
vForce.sqrt(x,
result: &buffer)
initializedCount = n
}Topics
Swift Overlay
Array-Oriented Arithmetic and Auxiliary Functions
ceil(_:)ceil(_:)ceil(_:result:)ceil(_:result:)copysign(magnitudes:signs:)copysign(magnitudes:signs:)copysign(magnitudes:signs:result:)copysign(magnitudes:signs:result:)floor(_:)floor(_:)floor(_:result:)floor(_:result:)nearestInteger(_:)nearestInteger(_:)nearestInteger(_:result:)nearestInteger(_:result:)reciprocal(_:)reciprocal(_:)reciprocal(_:result:)reciprocal(_:result:)remainder(dividends:divisors:)remainder(dividends:divisors:)remainder(dividends:divisors:result:)remainder(dividends:divisors:result:)rsqrt(_:)rsqrt(_:)rsqrt(_:result:)rsqrt(_:result:)sqrt(_:)sqrt(_:)sqrt(_:result:)sqrt(_:result:)trunc(_:)trunc(_:)trunc(_:result:)trunc(_:result:)truncatingRemainder(dividends:divisors:)truncatingRemainder(dividends:divisors:)truncatingRemainder(dividends:divisors:result:)truncatingRemainder(dividends:divisors:result:)vvceil(_:_:_:)vvceilf(_:_:_:)vvfloor(_:_:_:)vvfloorf(_:_:_:)vvcopysign(_:_:_:_:)vvcopysignf(_:_:_:_:)vvdiv(_:_:_:_:)vvdivf(_:_:_:_:)vvfabs(_:_:_:)vvfabsf(_:_:_:)vvfmod(_:_:_:_:)vvfmodf(_:_:_:_:)vvremainder(_:_:_:_:)vvremainderf(_:_:_:_:)vvint(_:_:_:)vvintf(_:_:_:)vvnint(_:_:_:)vvnintf(_:_:_:)vvrsqrt(_:_:_:)vvrsqrtf(_:_:_:)vvsqrt(_:_:_:)vvsqrtf(_:_:_:)vvrec(_:_:_:)vvrecf(_:_:_:)vvnextafter(_:_:_:_:)vvnextafterf(_:_:_:_:)
Array-Oriented Exponential and Logarithmic Functions
exp(_:)exp(_:)exp(_:result:)exp(_:result:)exp2(_:)exp2(_:)exp2(_:result:)exp2(_:result:)expm1(_:)expm1(_:)expm1(_:result:)expm1(_:result:)log10(_:)log(_:)log(_:)log(_:result:)log(_:result:)log1p(_:)log1p(_:)log1p(_:result:)log1p(_:result:)log10(_:)log10(_:result:)log10(_:result:)log2(_:)log2(_:)log2(_:result:)log2(_:result:)logb(_:)logb(_:)logb(_:result:)logb(_:result:)vvexp(_:_:_:)vvexpf(_:_:_:)vvexp2(_:_:_:)vvexp2f(_:_:_:)vvexpm1(_:_:_:)vvexpm1f(_:_:_:)vvlog(_:_:_:)vvlogf(_:_:_:)vvlog1p(_:_:_:)vvlog1pf(_:_:_:)vvlog2(_:_:_:)vvlog2f(_:_:_:)vvlog10(_:_:_:)vvlog10f(_:_:_:)vvlogb(_:_:_:)vvlogbf(_:_:_:)
Array-Oriented Power Functions
pow(bases:exponents:)pow(bases:exponents:)pow(bases:exponents:result:)pow(bases:exponents:result:)vvpow(_:_:_:_:)vvpowf(_:_:_:_:)
Array-Oriented Trigonometric Functions
acos(_:)acos(_:)acos(_:result:)acos(_:result:)asin(_:)asin(_:)asin(_:result:)asin(_:result:)atan(_:)atan(_:)atan(_:result:)atan(_:result:)atan2(x:y:)atan2(x:y:)atan2(x:y:result:)atan2(x:y:result:)cos(_:)cos(_:)cos(_:result:)cos(_:result:)cosPi(_:)cosPi(_:)cosPi(_:result:)cosPi(_:result:)sin(_:)sin(_:)sin(_:result:)sin(_:result:)sinPi(_:)sinPi(_:)sinPi(_:result:)sinPi(_:result:)sincos(_:sinResult:cosResult:)sincos(_:sinResult:cosResult:)tan(_:)tan(_:)tan(_:result:)tan(_:result:)tanPi(_:)tanPi(_:)tanPi(_:result:)tanPi(_:result:)vvsin(_:_:_:)vvsinf(_:_:_:)vvsinpi(_:_:_:)vvsinpif(_:_:_:)vvcos(_:_:_:)vvcosf(_:_:_:)vvcospi(_:_:_:)vvcospif(_:_:_:)vvcosisin(_:_:_:)vvcosisinf(_:_:_:)vvsincos(_:_:_:_:)vvsincosf(_:_:_:_:)vvtan(_:_:_:)vvtanf(_:_:_:)vvtanpi(_:_:_:)vvtanpif(_:_:_:)vvasin(_:_:_:)vvasinf(_:_:_:)vvacos(_:_:_:)vvacosf(_:_:_:)vvatan(_:_:_:)vvatanf(_:_:_:)vvatan2(_:_:_:_:)vvatan2f(_:_:_:_:)
Array-Oriented Hyperbolic Functions
acosh(_:)acosh(_:)acosh(_:result:)acosh(_:result:)asinh(_:)asinh(_:)asinh(_:result:)asinh(_:result:)atanh(_:)atanh(_:)atanh(_:result:)atanh(_:result:)cosh(_:)cosh(_:)cosh(_:result:)cosh(_:result:)sinh(_:)sinh(_:)sinh(_:result:)sinh(_:result:)tanh(_:)tanh(_:)tanh(_:result:)tanh(_:result:)vvsinh(_:_:_:)vvsinhf(_:_:_:)vvcosh(_:_:_:)vvcoshf(_:_:_:)vvtanh(_:_:_:)vvtanhf(_:_:_:)vvasinh(_:_:_:)vvasinhf(_:_:_:)vvacosh(_:_:_:)vvacoshf(_:_:_:)vvatanh(_:_:_:)vvatanhf(_:_:_:)