Determines if the given double value is zero (according to the precision) or not - Java java.lang

Java examples for java.lang:double

Description

Determines if the given double value is zero (according to the precision) or not

Demo Code


//package com.java2s;

public class Main {
    /**/*from   w ww  . j  a v a  2s .c  o  m*/
     * Precision for considering two double values equivalents
     */
    public static final double PRECISION = 1e-10;

    /**
     * Determines if the given double value is zero (according to the precision) or not
     * @param x double value to be analized
     * @return <i>true</i> if <i>abs(x) <= precision</i>, <i>false</i> otherwise
     */
    public static boolean isZero(double x) {
        return (Math.abs(x) <= PRECISION);
    }
}

Related Tutorials