Blame view

vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Engineering/Compare.php 2.19 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  <?php
  
  namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
  
  use PhpOffice\PhpSpreadsheet\Calculation\Exception;
  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);
  
          try {
              $a = EngineeringValidations::validateFloat($a);
              $b = EngineeringValidations::validateFloat($b);
          } catch (Exception $e) {
              return $e->getMessage();
          }
  
          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);
  
          try {
              $number = EngineeringValidations::validateFloat($number);
              $step = EngineeringValidations::validateFloat($step);
          } catch (Exception $e) {
              return $e->getMessage();
          }
  
          return (int) ($number >= $step);
      }
  }