Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BcMathCalculator.php

class BcMathCalculator

Calculator implementation built around the bcmath library.

@internal

@psalm-immutable

Hierarchy

  • class \Brick\Math\Internal\Calculator
    • class \Brick\Math\Internal\Calculator\BcMathCalculator extends \Brick\Math\Internal\Calculator

Expanded class hierarchy of BcMathCalculator

File

vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php, line 16

Namespace

Brick\Math\Internal\Calculator
View source
class BcMathCalculator extends Calculator {
    public function add(string $a, string $b) : string {
        return \bcadd($a, $b, 0);
    }
    public function sub(string $a, string $b) : string {
        return \bcsub($a, $b, 0);
    }
    public function mul(string $a, string $b) : string {
        return \bcmul($a, $b, 0);
    }
    public function divQ(string $a, string $b) : string {
        return \bcdiv($a, $b, 0);
    }
    public function divR(string $a, string $b) : string {
        return \bcmod($a, $b, 0);
    }
    public function divQR(string $a, string $b) : array {
        $q = \bcdiv($a, $b, 0);
        $r = \bcmod($a, $b, 0);
        return [
            $q,
            $r,
        ];
    }
    public function pow(string $a, int $e) : string {
        return \bcpow($a, (string) $e, 0);
    }
    public function modPow(string $base, string $exp, string $mod) : string {
        return \bcpowmod($base, $exp, $mod, 0);
    }
    public function sqrt(string $n) : string {
        return \bcsqrt($n, 0);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
BcMathCalculator::add public function Adds two numbers. Overrides Calculator::add
BcMathCalculator::divQ public function Returns the quotient of the division of two numbers. Overrides Calculator::divQ
BcMathCalculator::divQR public function Returns the quotient and remainder of the division of two numbers. Overrides Calculator::divQR
BcMathCalculator::divR public function Returns the remainder of the division of two numbers. Overrides Calculator::divR
BcMathCalculator::modPow public function Raises a number into power with modulo. Overrides Calculator::modPow
BcMathCalculator::mul public function Multiplies two numbers. Overrides Calculator::mul
BcMathCalculator::pow public function Exponentiates a number. Overrides Calculator::pow
BcMathCalculator::sqrt public function Returns the square root of the given number, rounded down. Overrides Calculator::sqrt
BcMathCalculator::sub public function Subtracts two numbers. Overrides Calculator::sub
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::and public function Calculates bitwise AND of two numbers. 1
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::fromBase public function Converts a number from an arbitrary base. 1
Calculator::gcd public function Returns the greatest common divisor of the two numbers. 1
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::modInverse public function Returns the modular multiplicative inverse of $x modulo $m. 1
Calculator::neg final public function Negates a number.
Calculator::or public function Calculates bitwise OR of two numbers. 1
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::toBase public function Converts a number to an arbitrary base. 1
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
Calculator::xor public function Calculates bitwise XOR of two numbers. 1

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal