: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Will take any real positive number and solve for it's factorial. Eg.
* `5!` will become `1*2*3*4*5` = `120` For integers
* 5.2! will become gamma(6.2) for non-integers
* Solve for non-integer factorials 2015/07/02
* @param Float $num Non-negative real number to get factorial of
* @throws Exception if number is at or less than 0
* @return Float Solved factorial
protected function factorial($num) {
throw new Exception("Factorial Error: Factorials don't exist for numbers < 0", NF_EOS_Parser::E_NAN);
//A non-integer! Gamma that sucker up!
if(intval($num) != $num) {
return $this->gamma($num + 1);
for($i=1;$i<=$num;$i++) {
} //end function factorial
* Because we can. This function exists as a catch-all for different
* numerical approx. of gamma if I decide to add any past Lanczos'.
* This method is public because a function doesn't currently exist
* within this parser to use it. That will change in the future.
* @param $z Number to compute gamma from
* @return Float The gamma (hopefully, I'll test it after writing the code)
public function gamma($z)
return $this->laGamma($z);
* The Lanczos Approximation method of finding gamma values
* @link http://www.rskey.org/CMS/index.php/the-library/11
* @link http://algolist.manual.ru/maths/count_fast/gamma_function.php
* @link https://en.wikipedia.org/wiki/Lanczos_approximation
* @param float $z Number to obtain the gamma of
* @return float Gamma of inputted number
* @throws Exception if Number is less than or equal to 0
protected function laGamma($z)
//check validity of $z, throw error if not a valid number to be used with gamma
throw new Exception("Gamma cannot be calculated on numbers less than or equal to 0", NF_EOS_Parser::E_NAN);
5 => 1.208650973866179E-3,
// ((sqrt(2pi)/z)(p[0]+sum(p[n]/(z+n), 1, 6)))(z+5.5)^(z+0.5)*e^(-(z+5.5))
//Next comes our summation
// Don't forget to add p[0] to it...
$g3 = pow($z+5.5, $z + .5);
//now just multiply them all together
$gamma = $g1 * $g2 * $g3 * $g4;