vForce

Perform transcendental and trigonometric functions on vectors of any length.

Overview

The vForce.h header file declares a set of trigonometric and transcendental functions in terms of C arrays (double * or float *), which can be of any length. Internally, the functions are vectorized for the current architecture.

The functions declared in vForce.h have the customary mathematical names, but with the prefix "vv." Each mathematical function is available in two variants: one for single-precision floating-point data and one for double-precision data. The single-precision forms have the suffix "f," while the double-precision forms have no suffix. For example, vvcosf is the single-precision cosine function, while vvcos is the double-precision variant.

All of the vForce.h 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

vForce 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, containing single-precision values, the following code uses map(_:) to create a second array, y, containing the square root of each array element.

var x = [Float]()

for _ in 0...10_000_000 {
    x.append(Float(drand48() * 1_000_000))
}

let y = x.map{
    return sqrt($0)
}

The equivalent functionality implemented in vForce runs significantly faster:

var n = Int32(x.count)
var y = [Float](repeating: 0, count: x.count)

vvsqrtf(&y, x, &n)

Topics

Array-Oriented Arithmetic and Auxiliary Functions

func vvceil(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the ceiling of each element in an array of double-precision values.

func vvceilf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the ceiling of each element in an array of single-precision values.

func vvfloor(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the floor of each element in an array of double-precision values.

func vvfloorf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the floor of each element in an array of single-precision values.

func vvcopysign(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Copies an array, setting the sign of each element based on a second array of double-precision values.

func vvcopysignf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Copies an array, setting the sign of each element based on a second array of single-precision values.

func vvdiv(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Divides each element in an array by the corresponding value in a second array of double-precision values.

func vvdivf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Divides each element in an array by the corresponding value in a second array of single-precision values.

func vvfabs(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the absolute value for each element in an array of double-precision values.

func vvfabsf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the absolute value for each element in an array of single-precision values.

func vvfmod(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the modulus after dividing each element in an array by the corresponding element in a second array of double-precision values.

func vvfmodf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the modulus after dividing each element in an array by the corresponding element in a second array of single-precision values.

func vvremainder(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the remainder after dividing each element in an array by the corresponding element in a second array of double-precision values.

func vvremainderf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the remainder after dividing each element in an array by the corresponding element in a second array of single-precision values.

func vvint(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the integer truncation for each element in an array of double-precision values.

func vvintf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the integer truncation for each element in an array of single-precision values.

func vvnint(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the nearest integer for each element in an array of double-precision values.

func vvnintf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the nearest integer for each element in an array of single-precision values.

func vvrsqrt(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the reciprocal square root of each element in an array of double-precision values.

func vvrsqrtf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the reciprocal square root of each element in an array of single-precision values.

func vvsqrt(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the square root of each element in an array of double-precision values.

func vvsqrtf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the square root of each element in an array of single-precision values.

func vvrec(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the reciprocal of each element in an array of double-precision values.

func vvrecf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the reciprocal of each element in an array of single-precision values.

func vvnextafter(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the next machine-representable value for each element in an array of double-precision values.

func vvnextafterf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the next machine-representable value for each element in an array of single-precision values.

Array-Oriented Exponential and Logarithmic Functions

func vvexp(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates e raised to the power of each element in an array of double-precision values.

func vvexpf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates e raised to the power of each element in an array of single-precision values.

func vvexp2(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates 2 raised to the power of each element in an array of double-precision values.

func vvexp2f(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates 2 raised to the power of each element in an array of single-precision values.

func vvexpm1(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates eˣ-1 for each element in an array of double-precision values.

func vvexpm1f(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates eˣ-1 for each element in an array of single-precision values.

func vvlog(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the natural logarithm for each element in an array of double-precision values.

func vvlogf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the natural logarithm for each element in an array of single-precision values.

func vvlog1p(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates log(1+x) for each element in an array of double-precision values.

func vvlog1pf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates log(1+x) for each element in an array of single-precision values.

func vvlog2(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the base 2 logarithm of each element in an array of double-precision values.

func vvlog2f(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the base 2 logarithm of each element in an array of single-precision values.

func vvlog10(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the base 10 logarithm of each element in an array of double-precision values.

func vvlog10f(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the base 10 logarithm of each element in an array of single-precision values.

func vvlogb(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the unbiased exponent of each element in an array of double-precision values.

func vvlogbf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the unbiased exponent of each element in an array of single-precision values.

Array-Oriented Power Functions

func vvpow(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Raises each element in an array to the power of the corresponding element in a second array of double-precision values.

func vvpowf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Raises each element in an array to the power of the corresponding element in a second array of single-precision values.

Array-Oriented Trigonometric Functions

func vvsin(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the sine of each element in an array of double-precision values.

func vvsinf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the sine of each element in an array of single-precision values.

func vvsinpi(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the sine of pi multiplied by each element in an array of double-precision values.

func vvsinpif(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the sine of pi multiplied by each element in an array of single-precision values.

func vvcos(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the cosine of each element in an array of double-precision values.

func vvcosf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the cosine of each element in an array of single-precision values.

func vvcospi(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the cosine of pi multiplied by each element in an array of double-precision values.

func vvcospif(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the cosine of pi multiplied by each element in an array of single-precision values.

func vvcosisin(OpaquePointer, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the cosine and sine of each element in an array of double-precision values.

func vvcosisinf(OpaquePointer, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the cosine and sine of each element in an array of single-precision values.

func vvsincos(UnsafeMutablePointer<Double>, UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the cosine and sine of each element in an array of double-precision values.

func vvsincosf(UnsafeMutablePointer<Float>, UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the cosine and sine of each element in an array of single-precision values.

func vvtan(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the tangent of each element in an array of double-precision values.

func vvtanf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the tangent of each element in an array of single-precision values.

func vvtanpi(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the tangent of pi multiplied by each element in an array of double-precision values.

func vvtanpif(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the tangent of pi multiplied by each element in an array of single-precision values.

func vvasin(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the arcsine of each element in an array of double-precision values.

func vvasinf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the arcsine of each element in an array of single-precision values.

func vvacos(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the arccosine of each element in an array of double-precision values.

func vvacosf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the arccosine of each element in an array of single-precision values.

func vvatan(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the arctangent of each element in an array of double-precision values.

func vvatanf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the arctangent of each element in an array of single-precision values.

func vvatan2(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the arctangent of each pair of elements in two arrays of double-precision values.

func vvatan2f(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the arctangent of each pair of elements in two arrays of single-precision values.

Array-Oriented Hyperbolic Functions

func vvsinh(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the hyperbolic sine of each element in an array of double-precision values.

func vvsinhf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the hyperbolic sine of each element in an array of single-precision values.

func vvcosh(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the hyperbolic cosine of each element in an array of double-precision values.

func vvcoshf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the hyperbolic cosine of each element in an array of single-precision values.

func vvtanh(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the hyperbolic tangent of each element in an array of double-precision values.

func vvtanhf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the hyperbolic tangent of each element in an array of single-precision values.

func vvasinh(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the inverse hyperbolic sine of each element in an array of double-precision values.

func vvasinhf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the inverse hyperbolic sine of each element in an array of single-precision values.

func vvacosh(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the inverse hyperbolic cosine of each element in an array of double-precision values.

func vvacoshf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the inverse hyperbolic cosine of each element in an array of single-precision values.

func vvatanh(UnsafeMutablePointer<Double>, UnsafePointer<Double>, UnsafePointer<Int32>)

Calculates the inverse hyperbolic tangent of each element in an array of double-precision values.

func vvatanhf(UnsafeMutablePointer<Float>, UnsafePointer<Float>, UnsafePointer<Int32>)

Calculates the inverse hyperbolic tangent of each element in an array of single-precision values.