[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/brick/math/src/Internal/ -> Calculator.php (summary)

Performs basic operations on arbitrary size integers. Unless otherwise specified, all parameters must be validated as non-empty strings of digits, without leading zero, and with an optional leading minus sign if the number is not zero.

File Size: 756 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 23 functions

  set()
  get()
  detect()
  init()
  abs()
  neg()
  cmp()
  mod()
  modInverse()
  gcd()
  gcdExtended()
  fromBase()
  toBase()
  fromArbitraryBase()
  toArbitraryBase()
  divRound()
  and()
  or()
  xor()
  bitwise()
  twosComplement()
  toBinary()
  toDecimal()

Functions
Functions that are not part of a class:

set(?Calculator $calculator)   X-Ref
Sets the Calculator instance to use.

An instance is typically set only in unit tests: the autodetect is usually the best option.

param: Calculator|null $calculator The calculator instance, or NULL to revert to autodetect.
return: void

get()   X-Ref
Returns the Calculator instance to use.

If none has been explicitly set, the fastest available implementation will be returned.

return: Calculator

detect()   X-Ref
Returns the fastest available Calculator implementation.

return: Calculator

init(string $a, string $b)   X-Ref
Extracts the sign & digits of the operands.

param: string $a The first operand.
param: string $b The second operand.
return: array{0: bool, 1: bool, 2: string, 3: string} Whether $a and $b are negative, followed by their digits.

abs(string $n)   X-Ref
Returns the absolute value of a number.

param: string $n The number.
return: string The absolute value.

neg(string $n)   X-Ref
Negates a number.

param: string $n The number.
return: string The negated value.

cmp(string $a, string $b)   X-Ref
Compares two numbers.

param: string $a The first number.
param: string $b The second number.
return: int [-1, 0, 1] If the first number is less than, equal to, or greater than the second number.

mod(string $a, string $b)   X-Ref

param: string $a
param: string $b The modulus; must not be zero.
return: string

modInverse(string $x, string $m)   X-Ref
Returns the modular multiplicative inverse of $x modulo $m.

If $x has no multiplicative inverse mod m, this method must return null.

This method can be overridden by the concrete implementation if the underlying library has built-in support.

param: string $x
param: string $m The modulus; must not be negative or zero.
return: string|null

gcd(string $a, string $b)   X-Ref
Returns the greatest common divisor of the two numbers.

This method can be overridden by the concrete implementation if the underlying library
has built-in support for GCD calculations.

param: string $a The first number.
param: string $b The second number.
return: string The GCD, always positive, or zero if both arguments are zero.

gcdExtended(string $a, string $b, string &$x, string &$y)   X-Ref
No description

fromBase(string $number, int $base)   X-Ref
Converts a number from an arbitrary base.

This method can be overridden by the concrete implementation if the underlying library
has built-in support for base conversion.

param: string $number The number, positive or zero, non-empty, case-insensitively validated for the given base.
param: int    $base   The base of the number, validated from 2 to 36.
return: string The converted number, following the Calculator conventions.

toBase(string $number, int $base)   X-Ref
Converts a number to an arbitrary base.

This method can be overridden by the concrete implementation if the underlying library
has built-in support for base conversion.

param: string $number The number to convert, following the Calculator conventions.
param: int    $base   The base to convert to, validated from 2 to 36.
return: string The converted number, lowercase.

fromArbitraryBase(string $number, string $alphabet, int $base)   X-Ref
Converts a non-negative number in an arbitrary base using a custom alphabet, to base 10.

param: string $number   The number to convert, validated as a non-empty string,
param: string $alphabet The alphabet that contains every digit, validated as 2 chars minimum.
param: int    $base     The base of the number, validated from 2 to alphabet length.
return: string The number in base 10, following the Calculator conventions.

toArbitraryBase(string $number, string $alphabet, int $base)   X-Ref
Converts a non-negative number to an arbitrary base using a custom alphabet.

param: string $number   The number to convert, positive or zero, following the Calculator conventions.
param: string $alphabet The alphabet that contains every digit, validated as 2 chars minimum.
param: int    $base     The base to convert to, validated from 2 to alphabet length.
return: string The converted number in the given alphabet.

divRound(string $a, string $b, int $roundingMode)   X-Ref
Performs a rounded division.

Rounding is performed when the remainder of the division is not zero.

param: string $a            The dividend.
param: string $b            The divisor.
param: int    $roundingMode The rounding mode.
return: string

and(string $a, string $b)   X-Ref
Calculates bitwise AND of two numbers.

This method can be overridden by the concrete implementation if the underlying library
has built-in support for bitwise operations.

param: string $a
param: string $b
return: string

or(string $a, string $b)   X-Ref
Calculates bitwise OR of two numbers.

This method can be overridden by the concrete implementation if the underlying library
has built-in support for bitwise operations.

param: string $a
param: string $b
return: string

xor(string $a, string $b)   X-Ref
Calculates bitwise XOR of two numbers.

This method can be overridden by the concrete implementation if the underlying library
has built-in support for bitwise operations.

param: string $a
param: string $b
return: string

bitwise(string $operator, string $a, string $b)   X-Ref
Performs a bitwise operation on a decimal number.

param: string $operator The operator to use, must be "and", "or" or "xor".
param: string $a        The left operand.
param: string $b        The right operand.
return: string

twosComplement(string $number)   X-Ref

param: string $number A positive, binary number.
return: string

toBinary(string $number)   X-Ref
Converts a decimal number to a binary string.

param: string $number The number to convert, positive or zero, only digits.
return: string

toDecimal(string $bytes)   X-Ref
Returns the positive decimal representation of a binary number.

param: string $bytes The bytes representing the number.
return: string



Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer