| 1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
|
|
4 |
|
|
|
5 |
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
|
|
6 |
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
|
|
7 |
|
|
|
8 |
class Compare
|
|
|
9 |
{
|
|
|
10 |
use ArrayEnabled;
|
|
|
11 |
|
|
|
12 |
/**
|
|
|
13 |
* DELTA.
|
|
|
14 |
*
|
|
|
15 |
* Excel Function:
|
|
|
16 |
* DELTA(a[,b])
|
|
|
17 |
*
|
|
|
18 |
* Tests whether two values are equal. Returns 1 if number1 = number2; returns 0 otherwise.
|
|
|
19 |
* Use this function to filter a set of values. For example, by summing several DELTA
|
|
|
20 |
* functions you calculate the count of equal pairs. This function is also known as the
|
|
|
21 |
* Kronecker Delta function.
|
|
|
22 |
*
|
|
|
23 |
* @param array|bool|float|int|string $a the first number
|
|
|
24 |
* Or can be an array of values
|
|
|
25 |
* @param array|bool|float|int|string $b The second number. If omitted, b is assumed to be zero.
|
|
|
26 |
* Or can be an array of values
|
|
|
27 |
*
|
|
|
28 |
* @return array|int|string (string in the event of an error)
|
|
|
29 |
* If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
30 |
* with the same dimensions
|
|
|
31 |
*/
|
|
|
32 |
public static function DELTA(array|float|bool|string|int $a, array|float|bool|string|int $b = 0.0): array|string|int
|
|
|
33 |
{
|
|
|
34 |
if (is_array($a) || is_array($b)) {
|
|
|
35 |
return self::evaluateArrayArguments([self::class, __FUNCTION__], $a, $b);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
try {
|
|
|
39 |
$a = EngineeringValidations::validateFloat($a);
|
|
|
40 |
$b = EngineeringValidations::validateFloat($b);
|
|
|
41 |
} catch (Exception $e) {
|
|
|
42 |
return $e->getMessage();
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
return (int) (abs($a - $b) < 1.0e-15);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* GESTEP.
|
|
|
50 |
*
|
|
|
51 |
* Excel Function:
|
|
|
52 |
* GESTEP(number[,step])
|
|
|
53 |
*
|
|
|
54 |
* Returns 1 if number >= step; returns 0 (zero) otherwise
|
|
|
55 |
* Use this function to filter a set of values. For example, by summing several GESTEP
|
|
|
56 |
* functions you calculate the count of values that exceed a threshold.
|
|
|
57 |
*
|
|
|
58 |
* @param array|bool|float|int|string $number the value to test against step
|
|
|
59 |
* Or can be an array of values
|
|
|
60 |
* @param null|array|bool|float|int|string $step The threshold value. If you omit a value for step, GESTEP uses zero.
|
|
|
61 |
* Or can be an array of values
|
|
|
62 |
*
|
|
|
63 |
* @return array|int|string (string in the event of an error)
|
|
|
64 |
* If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
65 |
* with the same dimensions
|
|
|
66 |
*/
|
|
|
67 |
public static function GESTEP(array|float|bool|string|int $number, $step = 0.0): array|string|int
|
|
|
68 |
{
|
|
|
69 |
if (is_array($number) || is_array($step)) {
|
|
|
70 |
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $step);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
try {
|
|
|
74 |
$number = EngineeringValidations::validateFloat($number);
|
|
|
75 |
$step = EngineeringValidations::validateFloat($step ?? 0.0);
|
|
|
76 |
} catch (Exception $e) {
|
|
|
77 |
return $e->getMessage();
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
return (int) ($number >= $step);
|
|
|
81 |
}
|
|
|
82 |
}
|