3 * This file is part of the Comparator package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace SebastianBergmann\Comparator;
14 * Compares doubles for equality.
16 class DoubleComparator extends NumericComparator
19 * Smallest value available in PHP.
23 const EPSILON = 0.0000000001;
26 * Returns whether the comparator can compare two values.
28 * @param mixed $expected The first value to compare
29 * @param mixed $actual The second value to compare
32 public function accepts($expected, $actual)
34 return (is_double($expected) || is_double($actual)) && is_numeric($expected) && is_numeric($actual);
38 * Asserts that two values are equal.
40 * @param mixed $expected First value to compare
41 * @param mixed $actual Second value to compare
42 * @param float $delta Allowed numerical distance between two values to consider them equal
43 * @param bool $canonicalize Arrays are sorted before comparison when set to true
44 * @param bool $ignoreCase Case is ignored when set to true
46 * @throws ComparisonFailure
48 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
51 $delta = self::EPSILON;
54 parent::assertEquals($expected, $actual, $delta, $canonicalize, $ignoreCase);