Fused Multiply Add in Java



Write a Java program that takes three float/double ab and c and computes the a * b + c on an efficient way.

Java program to Fused Multiply Add

public class Main {

    public static void main(String[] args) {

        double x = 49.29d;
        double y = -28.58d;
        double z = 33.63d;
        
        double q = (x * y) + z;        
        double fma = Math.fma(x, y, z);

        System.out.println("non-fma: " + q);
        System.out.println("fma: " + fma);
    }

}

Output:

non-fma: -1375.0781999999997
fma: -1375.0782

Free Spring Boot Tutorial - 5 Hours Full Course


Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course

Comments