public function multiply($a, $b) { $times = Math::absSystem($b); for ($i = 0; $i < $times; $i++) { $a += $a; } return $b > 0 ? $a : -$a; }
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)]; } } }