class GmpCalculator
Calculator implementation built around the GMP library.
@internal
@psalm-immutable
Hierarchy
- class \Brick\Math\Internal\Calculator
- class \Brick\Math\Internal\Calculator\GmpCalculator extends \Brick\Math\Internal\Calculator
Expanded class hierarchy of GmpCalculator
File
-
vendor/
brick/ math/ src/ Internal/ Calculator/ GmpCalculator.php, line 16
Namespace
Brick\Math\Internal\CalculatorView source
class GmpCalculator extends Calculator {
public function add(string $a, string $b) : string {
return \gmp_strval(\gmp_add($a, $b));
}
public function sub(string $a, string $b) : string {
return \gmp_strval(\gmp_sub($a, $b));
}
public function mul(string $a, string $b) : string {
return \gmp_strval(\gmp_mul($a, $b));
}
public function divQ(string $a, string $b) : string {
return \gmp_strval(\gmp_div_q($a, $b));
}
public function divR(string $a, string $b) : string {
return \gmp_strval(\gmp_div_r($a, $b));
}
public function divQR(string $a, string $b) : array {
[
$q,
$r,
] = \gmp_div_qr($a, $b);
return [
\gmp_strval($q),
\gmp_strval($r),
];
}
public function pow(string $a, int $e) : string {
return \gmp_strval(\gmp_pow($a, $e));
}
public function modInverse(string $x, string $m) : ?string {
$result = \gmp_invert($x, $m);
if ($result === false) {
return null;
}
return \gmp_strval($result);
}
public function modPow(string $base, string $exp, string $mod) : string {
return \gmp_strval(\gmp_powm($base, $exp, $mod));
}
public function gcd(string $a, string $b) : string {
return \gmp_strval(\gmp_gcd($a, $b));
}
public function fromBase(string $number, int $base) : string {
return \gmp_strval(\gmp_init($number, $base));
}
public function toBase(string $number, int $base) : string {
return \gmp_strval($number, $base);
}
public function and(string $a, string $b) : string {
return \gmp_strval(\gmp_and($a, $b));
}
public function or(string $a, string $b) : string {
return \gmp_strval(\gmp_or($a, $b));
}
public function xor(string $a, string $b) : string {
return \gmp_strval(\gmp_xor($a, $b));
}
public function sqrt(string $n) : string {
return \gmp_strval(\gmp_sqrt($n));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
Calculator::$instance | private static | property | The Calculator instance in use. | |
Calculator::abs | final public | function | Returns the absolute value of a number. | |
Calculator::ALPHABET | public | constant | The alphabet for converting from and to base 2 to 36, lowercase. | |
Calculator::bitwise | private | function | Performs a bitwise operation on a decimal number. | |
Calculator::cmp | final public | function | Compares two numbers. | |
Calculator::detect | private static | function | Returns the fastest available Calculator implementation. | |
Calculator::divRound | final public | function | Performs a rounded division. | |
Calculator::fromArbitraryBase | final public | function | Converts a non-negative number in an arbitrary base using a custom alphabet, to base 10. | |
Calculator::gcdExtended | private | function | ||
Calculator::get | final public static | function | Returns the Calculator instance to use. | |
Calculator::init | final protected | function | Extracts the sign & digits of the operands. | |
Calculator::MAX_POWER | public | constant | The maximum exponent value allowed for the pow() method. | |
Calculator::mod | public | function | ||
Calculator::neg | final public | function | Negates a number. | |
Calculator::set | final public static | function | Sets the Calculator instance to use. | |
Calculator::toArbitraryBase | final public | function | Converts a non-negative number to an arbitrary base using a custom alphabet. | |
Calculator::toBinary | private | function | Converts a decimal number to a binary string. | |
Calculator::toDecimal | private | function | Returns the positive decimal representation of a binary number. | |
Calculator::twosComplement | private | function | ||
GmpCalculator::add | public | function | Adds two numbers. | Overrides Calculator::add |
GmpCalculator::and | public | function | Calculates bitwise AND of two numbers. | Overrides Calculator::and |
GmpCalculator::divQ | public | function | Returns the quotient of the division of two numbers. | Overrides Calculator::divQ |
GmpCalculator::divQR | public | function | Returns the quotient and remainder of the division of two numbers. | Overrides Calculator::divQR |
GmpCalculator::divR | public | function | Returns the remainder of the division of two numbers. | Overrides Calculator::divR |
GmpCalculator::fromBase | public | function | Converts a number from an arbitrary base. | Overrides Calculator::fromBase |
GmpCalculator::gcd | public | function | Returns the greatest common divisor of the two numbers. | Overrides Calculator::gcd |
GmpCalculator::modInverse | public | function | Returns the modular multiplicative inverse of $x modulo $m. | Overrides Calculator::modInverse |
GmpCalculator::modPow | public | function | Raises a number into power with modulo. | Overrides Calculator::modPow |
GmpCalculator::mul | public | function | Multiplies two numbers. | Overrides Calculator::mul |
GmpCalculator::or | public | function | Calculates bitwise OR of two numbers. | Overrides Calculator::or |
GmpCalculator::pow | public | function | Exponentiates a number. | Overrides Calculator::pow |
GmpCalculator::sqrt | public | function | Returns the square root of the given number, rounded down. | Overrides Calculator::sqrt |
GmpCalculator::sub | public | function | Subtracts two numbers. | Overrides Calculator::sub |
GmpCalculator::toBase | public | function | Converts a number to an arbitrary base. | Overrides Calculator::toBase |
GmpCalculator::xor | public | function | Calculates bitwise XOR of two numbers. | Overrides Calculator::xor |