diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 0ef11aa030..ae33e45cb8 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -839,7 +839,7 @@ class Calculation ], 'DELTA' => [ 'category' => Category::CATEGORY_ENGINEERING, - 'functionCall' => [Engineering::class, 'DELTA'], + 'functionCall' => [Engineering\Compare::class, 'DELTA'], 'argumentCount' => '1,2', ], 'DEVSQ' => [ @@ -954,7 +954,7 @@ class Calculation ], 'ERFC.PRECISE' => [ 'category' => Category::CATEGORY_ENGINEERING, - 'functionCall' => [Engineering::class, 'ERFC'], + 'functionCall' => [Engineering\ErfC::class, 'ERFC'], 'argumentCount' => '1', ], 'ERROR.TYPE' => [ @@ -1196,7 +1196,7 @@ class Calculation ], 'GESTEP' => [ 'category' => Category::CATEGORY_ENGINEERING, - 'functionCall' => [Engineering::class, 'GESTEP'], + 'functionCall' => [Engineering\Compare::class, 'GESTEP'], 'argumentCount' => '1,2', ], 'GETPIVOTDATA' => [ diff --git a/src/PhpSpreadsheet/Calculation/Engineering.php b/src/PhpSpreadsheet/Calculation/Engineering.php index 92b68807d9..d7ed6e31e4 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering.php +++ b/src/PhpSpreadsheet/Calculation/Engineering.php @@ -1091,24 +1091,23 @@ public static function IMPRODUCT(...$complexNumbers) * DELTA. * * Tests whether two values are equal. Returns 1 if number1 = number2; returns 0 otherwise. - * Use this function to filter a set of values. For example, by summing several DELTA - * functions you calculate the count of equal pairs. This function is also known as the - * Kronecker Delta function. + * Use this function to filter a set of values. For example, by summing several DELTA + * functions you calculate the count of equal pairs. This function is also known as the + * Kronecker Delta function. * * Excel Function: * DELTA(a[,b]) * + * @Deprecated 2.0.0 Use the DELTA() method in the Engineering\Compare class instead + * * @param float $a the first number * @param float $b The second number. If omitted, b is assumed to be zero. * - * @return int + * @return int|string (string in the event of an error) */ public static function DELTA($a, $b = 0) { - $a = Functions::flattenSingleValue($a); - $b = Functions::flattenSingleValue($b); - - return (int) ($a == $b); + return Engineering\Compare::DELTA($a, $b); } /** @@ -1119,20 +1118,18 @@ public static function DELTA($a, $b = 0) * * Returns 1 if number >= step; returns 0 (zero) otherwise * Use this function to filter a set of values. For example, by summing several GESTEP - * functions you calculate the count of values that exceed a threshold. + * functions you calculate the count of values that exceed a threshold. + * + * @Deprecated 2.0.0 Use the GESTEP() method in the Engineering\Compare class instead * * @param float $number the value to test against step - * @param float $step The threshold value. - * If you omit a value for step, GESTEP uses zero. + * @param float $step The threshold value. If you omit a value for step, GESTEP uses zero. * - * @return int + * @return int|string (string in the event of an error) */ public static function GESTEP($number, $step = 0) { - $number = Functions::flattenSingleValue($number); - $step = Functions::flattenSingleValue($step); - - return (int) ($number >= $step); + return Engineering\Compare::GESTEP($number, $step); } /** diff --git a/src/PhpSpreadsheet/Calculation/Engineering/Compare.php b/src/PhpSpreadsheet/Calculation/Engineering/Compare.php new file mode 100644 index 0000000000..d875174edd --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/Engineering/Compare.php @@ -0,0 +1,63 @@ += step; returns 0 (zero) otherwise + * Use this function to filter a set of values. For example, by summing several GESTEP + * functions you calculate the count of values that exceed a threshold. + * + * @param float $number the value to test against step + * @param float $step The threshold value. If you omit a value for step, GESTEP uses zero. + * + * @return int|string (string in the event of an error) + */ + public static function GESTEP($number, $step = 0) + { + $number = Functions::flattenSingleValue($number); + $step = Functions::flattenSingleValue($step); + + if (!is_numeric($number) || !is_numeric($step)) { + return Functions::VALUE(); + } + + return (int) ($number >= $step); + } +} diff --git a/tests/data/Calculation/Engineering/DELTA.php b/tests/data/Calculation/Engineering/DELTA.php index 828cc66ac6..0180c3b9ed 100644 --- a/tests/data/Calculation/Engineering/DELTA.php +++ b/tests/data/Calculation/Engineering/DELTA.php @@ -126,4 +126,9 @@ 1.5, 1.5, ], + [ + '#VALUE!', + 1, + true, + ], ]; diff --git a/tests/data/Calculation/Engineering/GESTEP.php b/tests/data/Calculation/Engineering/GESTEP.php index b98c66f1f0..db9bf6458b 100644 --- a/tests/data/Calculation/Engineering/GESTEP.php +++ b/tests/data/Calculation/Engineering/GESTEP.php @@ -406,4 +406,9 @@ 4.5, 4.5, ], + [ + '#VALUE!', + 1, + true, + ], ];