Contents

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

Array-Oriented Exponential and Logarithmic Functions

Array-Oriented Power Functions

Array-Oriented Trigonometric Functions

Array-Oriented Hyperbolic Functions

Data Types

See Also

Vectors, Matrices, and Quaternions