public static function almostEqual($a, $b, $epsilon = 0.0000000001)
    {
        $diff = abs($a - $b);

        if ($a === $b) {
            // just compare values, handles e.g. INF
            return true;
        } elseif ($a === 0.0 || $b === 0.0 || $diff < self::FLOAT_MIN) {
            // a or b is zero or both are extremely close to it
            // relative error is less meaningful here
            return $diff < ($epsilon * self::FLOAT_MIN);
        } else {
            // use relative error
            $abs_a = abs($a);
            $abs_b = abs($b);
            return $diff / ($abs_a + $abs_b) < $epsilon;
        }
    }
public static function almostEqual($a, $b, $epsilon = 0.0000000001)
    {
        $diff = abs($a - $b);

        if ($a === $b) {
            // just compare values, handles e.g. INF
            return true;
        } elseif ($a === 0.0 || $b === 0.0 || $diff < self::FLOAT_MIN) {
            // a or b is zero or both are extremely close to it
            // relative error is less meaningful here
            return $diff < ($epsilon * self::FLOAT_MIN);
        } else {
            // use relative error
            $abs_a = abs($a);
            $abs_b = abs($b);
            return $diff / ($abs_a + $abs_b) < $epsilon;
        }
    }
public static function almostEqual ( $ a , $ b , $ epsilon = 0.0000000001 ) { $ diff = abs ( $ a - $ b ) ; if ( $ a === $ b ) { // just compare values, handles e.g. INF return true ; } elseif ( $ a === 0.0 || $ b === 0.0 || $ diff < self :: FLOAT_MIN ) { // a or b is zero or both are extremely close to it // relative error is less meaningful here return $ diff < ( $ epsilon * self :: FLOAT_MIN ) ; } else { // use relative error $ abs_a = abs ( $ a ) ; $ abs_b = abs ( $ b ) ; return $ diff / ( $ abs_a + $ abs_b ) < $ epsilon ; } }
Compare two float values for equality.

@see http://floating-point-gui.de/errors/comparison/

@param float $a
@param float $b
@param float $epsilon delta when comparing unequal values

@return boolean true if float values are considered to be of equal value
Compare two float values for equality .