Example usage for java.lang StrictMath hypot

List of usage examples for java.lang StrictMath hypot

Introduction

In this page you can find the example usage for java.lang StrictMath hypot.

Prototype

public static double hypot(double x, double y) 

Source Link

Document

Returns sqrt(x2 +y2) without intermediate overflow or underflow.

Usage

From source file:Main.java

public static void main(String[] args) {
    double d1 = 3, d2 = 4, d3 = 6;

    System.out.println("hypotenuse value of  d1 and d2 = " + StrictMath.hypot(d1, d2));

    System.out.println("hypotenuse value of d2 and d3 = " + StrictMath.hypot(d2, d3));
}

From source file:org.esa.beam.util.math.FastMathPerformance.java

public void testHypot() {
    System.gc();//w w  w. j a v a2 s .c o m
    double x = 0;
    long time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        x += StrictMath.hypot(i * F1, i * F1);
    long strictTime = System.nanoTime() - time;

    System.gc();
    double y = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        y += FastMath.hypot(i * F1, i * F1);
    long fastTime = System.nanoTime() - time;

    System.gc();
    double z = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        z += Math.hypot(i * F1, i * F1);
    long mathTime = System.nanoTime() - time;

    report("hypot", x + y + z, strictTime, fastTime, mathTime);
}