ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ErfC.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 class ErfC
8 {
26  public static function ERFC($value)
27  {
28  $value = Functions::flattenSingleValue($value);
29 
30  if (is_numeric($value)) {
31  return self::erfcValue($value);
32  }
33 
34  return Functions::VALUE();
35  }
36 
37  //
38  // Private method to calculate the erfc value
39  //
40  private static $oneSqrtPi = 0.564189583547756287;
41 
42  private static function erfcValue($value)
43  {
44  if (abs($value) < 2.2) {
45  return 1 - Erf::erfValue($value);
46  }
47  if ($value < 0) {
48  return 2 - self::ERFC(-$value);
49  }
50  $a = $n = 1;
51  $b = $c = $value;
52  $d = ($value * $value) + 0.5;
53  $q1 = $q2 = $b / $d;
54  do {
55  $t = $a * $n + $b * $value;
56  $a = $b;
57  $b = $t;
58  $t = $c * $n + $d * $value;
59  $c = $d;
60  $d = $t;
61  $n += 0.5;
62  $q1 = $q2;
63  $q2 = $b / $d;
64  } while ((abs($q1 - $q2) / $q2) > Functions::PRECISION);
65 
66  return self::$oneSqrtPi * exp(-$value * $value) * $q2;
67  }
68 }
$n
Definition: RandomTest.php:85
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296