Skip to content

Instantly share code, notes, and snippets.

@fatihgune
Created December 6, 2020 16:45
Show Gist options
  • Save fatihgune/88dc2adf2e03fa280b739c7b21ccbe2e to your computer and use it in GitHub Desktop.
Save fatihgune/88dc2adf2e03fa280b739c7b21ccbe2e to your computer and use it in GitHub Desktop.
Cumulative Normal Distribution Calculation (PHP)
<?
/**
* @param mixed $x
* @return float|int
*/
public function cumNormDist($x)
{
$b1 = 0.319381530;
$b2 = -0.356563782;
$b3 = 1.781477937;
$b4 = -1.821255978;
$b5 = 1.330274429;
$p = 0.2316419;
$c = 0.39894228;
if ($x >= 0.0) {
$t = 1.0 / (1.0 + $p * $x);
return (1.0 - $c * exp(-$x * $x / 2.0) * $t *
($t * ($t * ($t * ($t * $b5 + $b4) + $b3) + $b2) + $b1));
}
$t = 1.0 / (1.0 - $p * $x);
return ($c * exp(-$x * $x / 2.0) * $t *
($t * ($t * ($t * ($t * $b5 + $b4) + $b3) + $b2) + $b1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment