See Release Notes
Long Term Support Release
Differences Between: [Versions 400 and 401]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; 4 5 use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; 6 use PhpOffice\PhpSpreadsheet\Calculation\Exception; 7 use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; 8 9 class Gamma extends GammaBase 10 { 11 use ArrayEnabled; 12 13 /** 14 * GAMMA. 15 * 16 * Return the gamma function value. 17 * 18 * @param mixed $value Float value for which we want the probability 19 * Or can be an array of values 20 * 21 * @return array|float|string The result, or a string containing an error 22 * If an array of numbers is passed as an argument, then the returned result will also be an array 23 * with the same dimensions 24 */ 25 public static function gamma($value) 26 { 27 if (is_array($value)) { 28 return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value); 29 } 30 31 try { 32 $value = DistributionValidations::validateFloat($value); 33 } catch (Exception $e) { 34 return $e->getMessage(); 35 } 36 37 if ((((int) $value) == ((float) $value)) && $value <= 0.0) { 38 return ExcelError::NAN(); 39 } 40 41 return self::gammaValue($value); 42 } 43 44 /** 45 * GAMMADIST. 46 * 47 * Returns the gamma distribution. 48 * 49 * @param mixed $value Float Value at which you want to evaluate the distribution 50 * Or can be an array of values 51 * @param mixed $a Parameter to the distribution as a float 52 * Or can be an array of values 53 * @param mixed $b Parameter to the distribution as a float 54 * Or can be an array of values 55 * @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false) 56 * Or can be an array of values 57 * 58 * @return array|float|string 59 * If an array of numbers is passed as an argument, then the returned result will also be an array 60 * with the same dimensions 61 */ 62 public static function distribution($value, $a, $b, $cumulative) 63 { 64 if (is_array($value) || is_array($a) || is_array($b) || is_array($cumulative)) { 65 return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $a, $b, $cumulative); 66 } 67 68 try { 69 $value = DistributionValidations::validateFloat($value); 70 $a = DistributionValidations::validateFloat($a); 71 $b = DistributionValidations::validateFloat($b); 72 $cumulative = DistributionValidations::validateBool($cumulative); 73 } catch (Exception $e) { 74 return $e->getMessage(); 75 } 76 77 if (($value < 0) || ($a <= 0) || ($b <= 0)) { 78 return ExcelError::NAN(); 79 } 80 81 return self::calculateDistribution($value, $a, $b, $cumulative); 82 } 83 84 /** 85 * GAMMAINV. 86 * 87 * Returns the inverse of the Gamma distribution. 88 * 89 * @param mixed $probability Float probability at which you want to evaluate the distribution 90 * Or can be an array of values 91 * @param mixed $alpha Parameter to the distribution as a float 92 * Or can be an array of values 93 * @param mixed $beta Parameter to the distribution as a float 94 * Or can be an array of values 95 * 96 * @return array|float|string 97 * If an array of numbers is passed as an argument, then the returned result will also be an array 98 * with the same dimensions 99 */ 100 public static function inverse($probability, $alpha, $beta) 101 { 102 if (is_array($probability) || is_array($alpha) || is_array($beta)) { 103 return self::evaluateArrayArguments([self::class, __FUNCTION__], $probability, $alpha, $beta); 104 } 105 106 try { 107 $probability = DistributionValidations::validateProbability($probability); 108 $alpha = DistributionValidations::validateFloat($alpha); 109 $beta = DistributionValidations::validateFloat($beta); 110 } catch (Exception $e) { 111 return $e->getMessage(); 112 } 113 114 if (($alpha <= 0.0) || ($beta <= 0.0)) { 115 return ExcelError::NAN(); 116 } 117 118 return self::calculateInverse($probability, $alpha, $beta); 119 } 120 121 /** 122 * GAMMALN. 123 * 124 * Returns the natural logarithm of the gamma function. 125 * 126 * @param mixed $value Float Value at which you want to evaluate the distribution 127 * Or can be an array of values 128 * 129 * @return array|float|string 130 * If an array of numbers is passed as an argument, then the returned result will also be an array 131 * with the same dimensions 132 */ 133 public static function ln($value) 134 { 135 if (is_array($value)) { 136 return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value); 137 } 138 139 try { 140 $value = DistributionValidations::validateFloat($value); 141 } catch (Exception $e) { 142 return $e->getMessage(); 143 } 144 145 if ($value <= 0) { 146 return ExcelError::NAN(); 147 } 148 149 return log(self::gammaValue($value)); 150 } 151 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body