Extract DELTA() and GESTEP() functions from the Engineering class into a dedicated Comparison classes (#1853)
* Extract DELTA() and GESTEP() functions from the Engineering class into a dedicated Comparison classes Retain the original methods in the Engineering class as stubs for BC, but deprecate them. They will be removed for PHPSpreadsheet v2 Note that unit tests still point to the Engineering class stubs; these should be modified to use the Erf and ErfC classes directly when the stubs are removed
This commit is contained in:
parent
15a5d13aba
commit
c54e3e9979
|
|
@ -839,7 +839,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'DELTA' => [
|
'DELTA' => [
|
||||||
'category' => Category::CATEGORY_ENGINEERING,
|
'category' => Category::CATEGORY_ENGINEERING,
|
||||||
'functionCall' => [Engineering::class, 'DELTA'],
|
'functionCall' => [Engineering\Compare::class, 'DELTA'],
|
||||||
'argumentCount' => '1,2',
|
'argumentCount' => '1,2',
|
||||||
],
|
],
|
||||||
'DEVSQ' => [
|
'DEVSQ' => [
|
||||||
|
|
@ -954,7 +954,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'ERFC.PRECISE' => [
|
'ERFC.PRECISE' => [
|
||||||
'category' => Category::CATEGORY_ENGINEERING,
|
'category' => Category::CATEGORY_ENGINEERING,
|
||||||
'functionCall' => [Engineering::class, 'ERFC'],
|
'functionCall' => [Engineering\ErfC::class, 'ERFC'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ERROR.TYPE' => [
|
'ERROR.TYPE' => [
|
||||||
|
|
@ -1196,7 +1196,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'GESTEP' => [
|
'GESTEP' => [
|
||||||
'category' => Category::CATEGORY_ENGINEERING,
|
'category' => Category::CATEGORY_ENGINEERING,
|
||||||
'functionCall' => [Engineering::class, 'GESTEP'],
|
'functionCall' => [Engineering\Compare::class, 'GESTEP'],
|
||||||
'argumentCount' => '1,2',
|
'argumentCount' => '1,2',
|
||||||
],
|
],
|
||||||
'GETPIVOTDATA' => [
|
'GETPIVOTDATA' => [
|
||||||
|
|
|
||||||
|
|
@ -1098,17 +1098,16 @@ class Engineering
|
||||||
* Excel Function:
|
* Excel Function:
|
||||||
* DELTA(a[,b])
|
* 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 $a the first number
|
||||||
* @param float $b The second number. If omitted, b is assumed to be zero.
|
* @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)
|
public static function DELTA($a, $b = 0)
|
||||||
{
|
{
|
||||||
$a = Functions::flattenSingleValue($a);
|
return Engineering\Compare::DELTA($a, $b);
|
||||||
$b = Functions::flattenSingleValue($b);
|
|
||||||
|
|
||||||
return (int) ($a == $b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1121,18 +1120,16 @@ class Engineering
|
||||||
* Use this function to filter a set of values. For example, by summing several GESTEP
|
* 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.
|
||||||
*
|
*
|
||||||
* @param float $number the value to test against step
|
* @Deprecated 2.0.0 Use the GESTEP() method in the Engineering\Compare class instead
|
||||||
* @param float $step The threshold value.
|
|
||||||
* If you omit a value for step, GESTEP uses zero.
|
|
||||||
*
|
*
|
||||||
* @return int
|
* @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)
|
public static function GESTEP($number, $step = 0)
|
||||||
{
|
{
|
||||||
$number = Functions::flattenSingleValue($number);
|
return Engineering\Compare::GESTEP($number, $step);
|
||||||
$step = Functions::flattenSingleValue($step);
|
|
||||||
|
|
||||||
return (int) ($number >= $step);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
|
class Compare
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* DELTA.
|
||||||
|
*
|
||||||
|
* Excel Function:
|
||||||
|
* DELTA(a[,b])
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param float $a the first number
|
||||||
|
* @param float $b The second number. If omitted, b is assumed to be zero.
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
|
||||||
|
if (!is_numeric($a) || !is_numeric($b)) {
|
||||||
|
return Functions::VALUE();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) ($a == $b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GESTEP.
|
||||||
|
*
|
||||||
|
* Excel Function:
|
||||||
|
* GESTEP(number[,step])
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -126,4 +126,9 @@ return [
|
||||||
1.5,
|
1.5,
|
||||||
1.5,
|
1.5,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -406,4 +406,9 @@ return [
|
||||||
4.5,
|
4.5,
|
||||||
4.5,
|
4.5,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue