fix float limits

This commit is contained in:
Dennis Eichhorn 2020-10-06 21:49:29 +02:00
parent ef2ad3d19f
commit 7b06f33496
2 changed files with 16 additions and 16 deletions

View File

@ -99,8 +99,8 @@ final class Beta
$pMinus = $p - 1.0;
$h = 1.0 - $pqSum * $x / $pPlus;
if (\abs($h) < 2.23e-308) {
$h = 2.23e-308;
if (\abs($h) < 1.18e-37) {
$h = 1.18e-37;
}
$h = 1.0 / $h;
@ -112,33 +112,33 @@ final class Beta
$m2 = 2 * $m;
$d = $m * ($q - $m) * $x / (($pMinus + $m2) * ($p + $m2));
$h = 1.0 + $d * $h;
if (\abs($h) < 2.23e-308) {
$h = 2.23e-308;
if (\abs($h) < 1.18e-37) {
$h = 1.18e-37;
}
$h = 1.0 / $h;
$c = 1.0 + $d / $c;
if (\abs($c) < 2.23e-308) {
$c = 2.23e-308;
if (\abs($c) < 1.18e-37) {
$c = 1.18e-37;
}
$frac *= $h * $c;
$d = -($p + $m) * ($pqSum + $m) * $x / (($p + $m2) * ($pPlus + $m2));
$h = 1.0 + $d * $h;
if (\abs($h) < 2.23e-308) {
$h = 2.23e-308;
if (\abs($h) < 1.18e-37) {
$h = 1.18e-37;
}
$h = 1.0 / $h;
$c = 1.0 + $d / $c;
if (\abs($c) < 2.23e-308) {
$c = 2.23e-308;
if (\abs($c) < 1.18e-37) {
$c = 1.18e-37;
}
$delta = $h * $c;
$frac *= $delta;
++$m;
} while ($m < 1000000000 && \abs($delta - 1.0) > 8.88e-16);
} while ($m < 1000000 && \abs($delta - 1.0) > 8.88e-16);
return $frac;
}

View File

@ -275,7 +275,7 @@ final class Gamma
private static function gammaFraction(float $a, float $x) : float
{
$b = $x + 1.0 - $a;
$c = 1.0 / 2.23e-308;
$c = 1.0 / 1.18e-37;
$d = 1.0 / $b;
$h = $d;
$del = 0.0;
@ -286,12 +286,12 @@ final class Gamma
$d = $an * $d + $b;
$c = $b + $an / $c;
if (\abs($c) < 2.23e-308) {
$c = 2.23e-308;
if (\abs($c) < 1.18e-37) {
$c = 1.18e-37;
}
if (\abs($d) < 2.23e-308) {
$d = 2.23e-308;
if (\abs($d) < 1.18e-37) {
$d = 1.18e-37;
}
$d = 1.0 / $d;