C# Tutorial C# Advanced C# References

C# Math - FusedMultiplyAdd() Method



The C# FusedMultiplyAdd() method returns (x*y) + z. If any of the argument is NaN, the method returns NaN.

Syntax

public static double FusedMultiplyAdd (double x, double y, double z); 

Parameters

x Specify the value to be multiplied with y.
y Specify the value to be multiplied with x.
z Specify the value to be added with x*y.

Return Value

Returns (x*y) + z.

Example:

In the example below, FusedMultiplyAdd() method returns (x*y) + z.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine("Math.FusedMultiplyAdd(2, 3, 10) = "
                      + Math.FusedMultiplyAdd(2, 3, 10)); 
    Console.WriteLine("Math.FusedMultiplyAdd(-2, 5, 10) = "
                      + Math.FusedMultiplyAdd(-2, 5, 10)); 
    Console.WriteLine("Math.FusedMultiplyAdd(2.1, 3.3, 55) = "
                      + Math.FusedMultiplyAdd(2.1, 3.3, 55)); 
    Console.WriteLine("Math.FusedMultiplyAdd(Double.NaN, 3.3, 55) = "
                      + Math.FusedMultiplyAdd(Double.NaN, 3.3, 55)); 
  }
}

The output of the above code will be:

Math.FusedMultiplyAdd(2, 3, 10) = 16
Math.FusedMultiplyAdd(-2, 5, 10) = 0
Math.FusedMultiplyAdd(2.1, 3.3, 55) = 61.93
Math.FusedMultiplyAdd(Double.NaN, 3.3, 55) = NaN

❮ C# Math Methods

5