StrictMath.fma(float, float, float) in Java

StrictMath.fma(float, float, float): This method is available in java.lang.StrictMath class of Java.

Syntax:

float java.lang.StrictMath.fma(float a, float b, float c)

This method takes three arguments of type float as its parameters. 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 float.

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 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, as if with unlimited range and precision, and rounded once to the nearest float value.

Exceptions: NA

Approach

Java

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

        float a = 19.78f, b = 1881.6f, c = 1991.78f;
        System.out.println(StrictMath.fma(a, b, c));
    }
}

Output:

39209.83


No comments:

Post a Comment