function Calculator::cmp
Compares two numbers.
@psalm-return -1|0|1
Return value
int -1 if the first number is less than, 0 if equal to, 1 if greater than the second number.
3 calls to Calculator::cmp()
- Calculator::divRound in vendor/
brick/ math/ src/ Internal/ Calculator.php - Performs a rounded division.
- Calculator::modInverse in vendor/
brick/ math/ src/ Internal/ Calculator.php - Returns the modular multiplicative inverse of $x modulo $m.
- NativeCalculator::sqrt in vendor/
brick/ math/ src/ Internal/ Calculator/ NativeCalculator.php - Adapted from https://cp-algorithms.com/num_methods/roots_newton.html
File
-
vendor/
brick/ math/ src/ Internal/ Calculator.php, line 135
Class
- Calculator
- Performs basic operations on arbitrary size integers.
Namespace
Brick\Math\InternalCode
public final function cmp(string $a, string $b) : int {
[
$aNeg,
$bNeg,
$aDig,
$bDig,
] = $this->init($a, $b);
if ($aNeg && !$bNeg) {
return -1;
}
if ($bNeg && !$aNeg) {
return 1;
}
$aLen = \strlen($aDig);
$bLen = \strlen($bDig);
if ($aLen < $bLen) {
$result = -1;
}
elseif ($aLen > $bLen) {
$result = 1;
}
else {
$result = $aDig <=> $bDig;
}
return $aNeg ? -$result : $result;
}