Documentation

Gamma extends GammaBase
in package
uses ArrayEnabled

Table of Contents

Constants

EPS  = 2.22E-16
LG_C  = [-0.001910444077728, 0.0008417138778129501, -0.0005952379913043012, 0.0007936507935003503, -0.0027777777777776816, 0.08333333333333333, 0.0057083835261]
LG_D1  = -0.5772156649015329
LG_D2  = 0.42278433509846713
LG_D4  = 1.791759469228055
LG_FRTBIG  = 2.25E+76
LG_P1  = [4.945235359296727, 201.8112620856775, 2290.8383738313464, 11319.672059033808, 28557.246356716354, 38484.962284437934, 26377.487876241954, 7225.813979700288]
LG_P2  = [4.974607845568932, 542.4138599891071, 15506.93864978365, 184793.29044456323, 1088204.7694688288, 3338152.96798703, 5106661.678927353, 3074109.0548505397]
LG_P4  = [14745.0216605994, 2426813.3694867045, 121475557.40450932, 2663432449.630977, 29403789566.34554, 170266573776.5399, 492612579337.7431, 560625185622.3951]
LG_Q1  = [67.48212550303778, 1113.3323938571993, 7738.757056935398, 27639.870744033407, 54993.102062261576, 61611.22180066002, 36351.2759150194, 8785.536302431014]
LG_Q2  = [183.03283993705926, 7765.049321445006, 133190.38279660742, 1136705.8213219696, 5267964.117437947, 13467014.543111017, 17827365.303532742, 9533095.591844354]
LG_Q4  = [2690.5301758708993, 639388.5654300093, 41355999.30241388, 1120872109.616148, 14886137286.788137, 101680358627.24382, 341747634550.73773, 446315818741.9713]
LOG_GAMMA_X_MAX_VALUE  = 2.55E+305
MAX_ITERATIONS  = 256
MAX_VALUE  = 1.2E+308
PNT68  = 0.6796875
SQRT2PI  = 2.5066282746310007

Properties

$arrayArgumentHelper  : ArrayArgumentHelper
$initializationNeeded  : bool
$logGammaCacheResult  : float
$logGammaCacheX  : float

Methods

distribution()  : array<string|int, mixed>|float|string
GAMMADIST.
gamma()  : array<string|int, mixed>|float|string
GAMMA.
gammaValue()  : float
incompleteGamma()  : float
inverse()  : array<string|int, mixed>|float|string
GAMMAINV.
ln()  : array<string|int, mixed>|float|string
GAMMALN.
logGamma()  : float
logGamma function.
calculateDistribution()  : float
calculateInverse()  : float|string
evaluateArrayArguments()  : array<string|int, mixed>
Handles array argument processing when the function accepts multiple arguments, and any of them can be an array argument.
evaluateArrayArgumentsIgnore()  : array<string|int, mixed>
Handles array argument processing when the function accepts multiple arguments, and any of them can be an array argument except for the one specified by ignore.
evaluateArrayArgumentsSubset()  : array<string|int, mixed>
Handles array argument processing when the function accepts multiple arguments, but only the first few (up to limit) can be an array arguments.
evaluateArrayArgumentsSubsetFrom()  : array<string|int, mixed>
Handles array argument processing when the function accepts multiple arguments, but only the last few (from start) can be an array arguments.
evaluateSingleArgumentArray()  : array<string|int, mixed>
Handles array argument processing when the function accepts a single argument that can be an array argument.
logGamma3()  : float
logGamma4()  : float
initialiseHelper()  : void
logGamma1()  : float
logGamma2()  : float
testFalse()  : bool

Constants

LG_C

private mixed LG_C = [-0.001910444077728, 0.0008417138778129501, -0.0005952379913043012, 0.0007936507935003503, -0.0027777777777776816, 0.08333333333333333, 0.0057083835261]

LG_D1

private mixed LG_D1 = -0.5772156649015329

LG_D2

private mixed LG_D2 = 0.42278433509846713

LG_D4

private mixed LG_D4 = 1.791759469228055

LG_FRTBIG

private mixed LG_FRTBIG = 2.25E+76

LG_P1

private mixed LG_P1 = [4.945235359296727, 201.8112620856775, 2290.8383738313464, 11319.672059033808, 28557.246356716354, 38484.962284437934, 26377.487876241954, 7225.813979700288]

LG_P2

private mixed LG_P2 = [4.974607845568932, 542.4138599891071, 15506.93864978365, 184793.29044456323, 1088204.7694688288, 3338152.96798703, 5106661.678927353, 3074109.0548505397]

LG_P4

private mixed LG_P4 = [14745.0216605994, 2426813.3694867045, 121475557.40450932, 2663432449.630977, 29403789566.34554, 170266573776.5399, 492612579337.7431, 560625185622.3951]

LG_Q1

private mixed LG_Q1 = [67.48212550303778, 1113.3323938571993, 7738.757056935398, 27639.870744033407, 54993.102062261576, 61611.22180066002, 36351.2759150194, 8785.536302431014]

LG_Q2

private mixed LG_Q2 = [183.03283993705926, 7765.049321445006, 133190.38279660742, 1136705.8213219696, 5267964.117437947, 13467014.543111017, 17827365.303532742, 9533095.591844354]

LG_Q4

private mixed LG_Q4 = [2690.5301758708993, 639388.5654300093, 41355999.30241388, 1120872109.616148, 14886137286.788137, 101680358627.24382, 341747634550.73773, 446315818741.9713]

LOG_GAMMA_X_MAX_VALUE

private mixed LOG_GAMMA_X_MAX_VALUE = 2.55E+305

MAX_ITERATIONS

private mixed MAX_ITERATIONS = 256

MAX_VALUE

private mixed MAX_VALUE = 1.2E+308

SQRT2PI

private mixed SQRT2PI = 2.5066282746310007

Properties

$initializationNeeded

private static bool $initializationNeeded = true

$logGammaCacheResult

private static float $logGammaCacheResult = 0.0

$logGammaCacheX

private static float $logGammaCacheX = 0.0

Methods

distribution()

GAMMADIST.

public static distribution(mixed $value, mixed $a, mixed $b, mixed $cumulative) : array<string|int, mixed>|float|string

Returns the gamma distribution.

Parameters
$value : mixed

Float Value at which you want to evaluate the distribution Or can be an array of values

$a : mixed

Parameter to the distribution as a float Or can be an array of values

$b : mixed

Parameter to the distribution as a float Or can be an array of values

$cumulative : mixed

Boolean value indicating if we want the cdf (true) or the pdf (false) Or can be an array of values

Return values
array<string|int, mixed>|float|string

If an array of numbers is passed as an argument, then the returned result will also be an array with the same dimensions

gamma()

GAMMA.

public static gamma(mixed $value) : array<string|int, mixed>|float|string

Return the gamma function value.

Parameters
$value : mixed

Float value for which we want the probability Or can be an array of values

Return values
array<string|int, mixed>|float|string

The result, or a string containing an error If an array of numbers is passed as an argument, then the returned result will also be an array with the same dimensions

gammaValue()

public static gammaValue(float $value) : float
Parameters
$value : float
Return values
float

incompleteGamma()

public static incompleteGamma(float $a, float $x) : float
Parameters
$a : float
$x : float
Return values
float

inverse()

GAMMAINV.

public static inverse(mixed $probability, mixed $alpha, mixed $beta) : array<string|int, mixed>|float|string

Returns the inverse of the Gamma distribution.

Parameters
$probability : mixed

Float probability at which you want to evaluate the distribution Or can be an array of values

$alpha : mixed

Parameter to the distribution as a float Or can be an array of values

$beta : mixed

Parameter to the distribution as a float Or can be an array of values

Return values
array<string|int, mixed>|float|string

If an array of numbers is passed as an argument, then the returned result will also be an array with the same dimensions

ln()

GAMMALN.

public static ln(mixed $value) : array<string|int, mixed>|float|string

Returns the natural logarithm of the gamma function.

Parameters
$value : mixed

Float Value at which you want to evaluate the distribution Or can be an array of values

Return values
array<string|int, mixed>|float|string

If an array of numbers is passed as an argument, then the returned result will also be an array with the same dimensions

logGamma()

logGamma function.

public static logGamma(float $x) : float

Original author was Jaco van Kooten. Ported to PHP by Paul Meagher.

The natural logarithm of the gamma function.
Based on public domain NETLIB (Fortran) code by W. J. Cody and L. Stoltz
Applied Mathematics Division
Argonne National Laboratory
Argonne, IL 60439

References:

  1. W. J. Cody and K. E. Hillstrom, 'Chebyshev Approximations for the Natural Logarithm of the Gamma Function,' Math. Comp. 21, 1967, pp. 198-203.
  2. K. E. Hillstrom, ANL/AMD Program ANLC366S, DGAMMA/DLGAMA, May, 1969.
  3. Hart, Et. Al., Computer Approximations, Wiley and sons, New York, 1968.

From the original documentation:

This routine calculates the LOG(GAMMA) function for a positive real argument X. Computation is based on an algorithm outlined in references 1 and 2. The program uses rational functions that theoretically approximate LOG(GAMMA) to at least 18 significant decimal digits. The approximation for X > 12 is from reference 3, while approximations for X < 12.0 are similar to those in reference 1, but are unpublished. The accuracy achieved depends on the arithmetic system, the compiler, the intrinsic functions, and proper selection of the machine-dependent constants.

Error returns:
The program returns the value XINF for X .LE. 0.0 or when overflow would occur. The computation is believed to be free of underflow and overflow.

Parameters
$x : float
Tags
version
1.1
author

Jaco van Kooten

Return values
float

MAX_VALUE for x < 0.0 or when overflow would occur, i.e. x > 2.55E305

calculateDistribution()

protected static calculateDistribution(float $value, float $a, float $b, bool $cumulative) : float
Parameters
$value : float
$a : float
$b : float
$cumulative : bool
Return values
float

calculateInverse()

protected static calculateInverse(float $probability, float $alpha, float $beta) : float|string
Parameters
$probability : float
$alpha : float
$beta : float
Return values
float|string

evaluateArrayArguments()

Handles array argument processing when the function accepts multiple arguments, and any of them can be an array argument.

protected static evaluateArrayArguments(callable $method, mixed ...$arguments) : array<string|int, mixed>

Example use for: ROUND() or DATE().

Parameters
$method : callable
$arguments : mixed
Return values
array<string|int, mixed>

evaluateArrayArgumentsIgnore()

Handles array argument processing when the function accepts multiple arguments, and any of them can be an array argument except for the one specified by ignore.

protected static evaluateArrayArgumentsIgnore(callable $method, int $ignore, mixed ...$arguments) : array<string|int, mixed>

Example use for: HLOOKUP() and VLOOKUP(), where argument 1 is a matrix that needs to be treated as a database rather than as an array argument.

Parameters
$method : callable
$ignore : int
$arguments : mixed
Return values
array<string|int, mixed>

evaluateArrayArgumentsSubset()

Handles array argument processing when the function accepts multiple arguments, but only the first few (up to limit) can be an array arguments.

protected static evaluateArrayArgumentsSubset(callable $method, int $limit, mixed ...$arguments) : array<string|int, mixed>

Example use for: NETWORKDAYS() or CONCATENATE(), where the last argument is a matrix (or a series of values) that need to be treated as a such rather than as an array arguments.

Parameters
$method : callable
$limit : int
$arguments : mixed
Return values
array<string|int, mixed>

evaluateArrayArgumentsSubsetFrom()

Handles array argument processing when the function accepts multiple arguments, but only the last few (from start) can be an array arguments.

protected static evaluateArrayArgumentsSubsetFrom(callable $method, int $start, mixed ...$arguments) : array<string|int, mixed>

Example use for: Z.TEST() or INDEX(), where the first argument 1 is a matrix that needs to be treated as a dataset rather than as an array argument.

Parameters
$method : callable
$start : int
$arguments : mixed
Return values
array<string|int, mixed>

evaluateSingleArgumentArray()

Handles array argument processing when the function accepts a single argument that can be an array argument.

protected static evaluateSingleArgumentArray(callable $method, array<string|int, mixed> $values) : array<string|int, mixed>

Example use for: DAYOFMONTH() or FACT().

Parameters
$method : callable
$values : array<string|int, mixed>
Return values
array<string|int, mixed>

logGamma3()

protected static logGamma3(float $y) : float
Parameters
$y : float
Return values
float

logGamma4()

protected static logGamma4(float $y) : float
Parameters
$y : float
Return values
float

initialiseHelper()

private static initialiseHelper(array<string|int, mixed>|false $arguments) : void
Parameters
$arguments : array<string|int, mixed>|false

Can be changed to array for Php8.1+

logGamma1()

private static logGamma1(float $y) : float
Parameters
$y : float
Return values
float

logGamma2()

private static logGamma2(float $y) : float
Parameters
$y : float
Return values
float

testFalse()

private static testFalse(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

        
On this page

Search results