fma() double in Java

fma(): This method is available in the Math class of Java.

Syntax:

double java.lang.Math.fma(double a, double b, double c)

This method takes three parameters of type double as its arguments. This method returns the fused multiply-add of the three arguments; that is, returns the exact product of the first two arguments summed with the third argument and then rounded once to the nearest double.

Special cases: 

1. If any argument is NaN, the result is NaN.

2.If one of the first two arguments is infinite and the other is zero, the result is NaN.

3.If the exact product of the first two arguments is infinite(in other words, at least one of the arguments is infinite and the other is neither zero nor NaN) and the third argument is an infinity of the opposite sign, the result is NaN.

Parameters: Three parameters are required for this method.

a: a value.

b: a value.

c: a value. 

Returns:(a × b + c) computed.

For Example:

Math.fma(5,6,10) = > It returns 40.0

Approach

Java

public class FmaDouble {
    public static void main(String[] args) {

        double a = 5, b = 6, c = 10;
        System.out.println(Math.fma(a, b, c));

    }
}

Output:

40.0

No comments:

Post a Comment