C# Math.FusedMultiplyAdd() – Examples

In this tutorial, we will learn about the C# Math.FusedMultiplyAdd() method, and learn how to use this method to compute the product of two numbers and adding a number to this product, as a single operation, with the help of examples.

FusedMultiplyAdd(Double, Double, Double)

Math.FusedMultiplyAdd(x, y, z) returns the result of (x * y) + z for given x, y and z.

Syntax

The syntax of FusedMultiplyAdd() method is

Math.FusedMultiplyAdd(Double x, Double y, Double z)

where

ParameterDescription
xFirst operand for multiplication.
ySecond operand for multiplication.
zThe value that is added to the product of x and y.

Return Value

The method returns result as Double value.

Example 1 – FusedMultiplyAdd(Double, Double, Double)

In this example, we will find the result of (x*y)+z for some combinations of x, y and z, using Math.FusedMultiplyAdd() method.

C# Program

using System;
 
class Example {
    static void Main(string[] args) {
        Double x, y, z, result;

        x = 2;
        y = 3;
        z = 1;
        result = Math.FusedMultiplyAdd(x, y, z);
        Console.WriteLine($"FusedMultiplyAdd({x}, {y}, {z}) = {result}");

        x = 10;
        y = 5;
        z = 3;
        result = Math.FusedMultiplyAdd(x, y, z);
        Console.WriteLine($"FusedMultiplyAdd({x}, {y}, {z}) = {result}");
    }
}

Output

FusedMultiplyAdd(2, 3, 1) = 7
FusedMultiplyAdd(10, 5, 3) = 53

Conclusion

In this C# Tutorial, we have learnt the syntax of C# Math.FusedMultiplyAdd() method, and also learnt how to use this method with the help of C# example programs.