public static function solveQuadraticEquation($a, $b, $c) { if ($b == 0 && $c <= 0) { $c = Math::absSystem($c); $c /= $a; $cSqrt = Math::squareRoot($c); return [0 => $cSqrt, 1 => -$cSqrt]; } $d = self::discriminant2($a, $b, $c); if ($d < 0) { return NULL; } else { if ($d == 0 || $a == 0) { return [0 => -$b / 2 * $a, 1 => NULL]; } else { return [0 => -$b + Math::squareRoot($d) / (2 * $a), 1 => -$b - Math::squareRoot($d) / (2 * $a)]; } } }
public static function sieveOfEratosthenes($number) { $sieve = []; $sieve[0] = $sieve[1] = TRUE; $squareRoot = Math::squareRoot($number); for ($i = 2; $i <= $squareRoot; $i++) { if ($sieve[$i] == TRUE) { continue; } for ($j = 2 * $i; $j < $number; $j += $i) { $sieve[$j] = TRUE; } } return $sieve; }
public static function getFibonacci($x) { static $gro5; $gro5 = Math::squareRoot(5); $fi = (1 + $gro5) / 2; return Math::power($fi, $x) / $gro5 - Math::power(1 - $fi, $x) / $gro5; }