Swift Tutorial Swift References

Swift - fma() Function



The Swift fma() function returns (x*y) + z. The function computes the result without losing precision and rounded only once to fit the result type.

Syntax

In Foundation framework, it is defined as follows:

public func fma(_ __x: Double, _ __y: Double, _ __z: Double) -> Double

Parameters

x Specify first value to multiplied.
y Specify second value to multiplied.
z Specify value to added.

Return Value

Returns (x*y) + z.

Example:

The example below shows the usage of fma() function.

import Foundation

var x:Double = 2.1
var y:Double = 4.2
var z:Double = 10.3

print("(x * y + z) = \(fma(x, y, z))")

The output of the above code will be:

(x * y + z) = 19.12

❮ Swift Math Functions