Joomla CMS  4.2.2
Documentation des API du CMS Joomla en version 4.2.2
Référence de la classe Calculator
+ Graphe d'héritage de Calculator:

Fonctions membres publiques

 abs (string $n)
 
 neg (string $n)
 
 cmp (string $a, string $b)
 
 add (string $a, string $b)
 
 sub (string $a, string $b)
 
 mul (string $a, string $b)
 
 divQ (string $a, string $b)
 
 divR (string $a, string $b)
 
 divQR (string $a, string $b)
 
 pow (string $a, int $e)
 
 mod (string $a, string $b)
 
 modInverse (string $x, string $m)
 
 modPow (string $base, string $exp, string $mod)
 
 gcd (string $a, string $b)
 
 sqrt (string $n)
 
 fromBase (string $number, int $base)
 
 toBase (string $number, int $base)
 
 fromArbitraryBase (string $number, string $alphabet, int $base)
 
 toArbitraryBase (string $number, string $alphabet, int $base)
 
 divRound (string $a, string $b, int $roundingMode)
 
 and (string $a, string $b)
 
 or (string $a, string $b)
 
 xor (string $a, string $b)
 

Fonctions membres publiques statiques

static set (?Calculator $calculator)
 
static get ()
 

Champs de données

const MAX_POWER = 1000000
 
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz'
 

Fonctions membres protégées

 init (string $a, string $b)
 

Fonctions membres privées

 gcdExtended (string $a, string $b, string &$x, string &$y)
 
 bitwise (string $operator, string $a, string $b)
 
 twosComplement (string $number)
 
 toBinary (string $number)
 
 toDecimal (string $bytes)
 

Fonctions membres privées statiques

static detect ()
 

Attributs privés statiques

static $instance
 

Description détaillée

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.

Any other parameter format will lead to undefined behaviour. All methods must return strings respecting this format, unless specified otherwise.

Documentation des fonctions membres

◆ abs()

abs ( string  $n)
final

Returns the absolute value of a number.

Paramètres
string$nThe number.
Renvoie
string The absolute value.

Références $n.

Référencé par Calculator\divRound(), Calculator\gcd(), et Calculator\modInverse().

◆ add()

add ( string  $a,
string  $b 
)
abstract

Adds two numbers.

Paramètres
string$aThe augend.
string$bThe addend.
Renvoie
string The sum.

Référencé par Calculator\divRound(), Calculator\fromArbitraryBase(), Calculator\mod(), Calculator\modInverse(), et Calculator\toDecimal().

◆ and()

and ( string  $a,
string  $b 
)

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ètres
string$a
string$b
Renvoie
string

Références $b, et Calculator\bitwise().

Référencé par Calculator\bitwise().

◆ bitwise()

bitwise ( string  $operator,
string  $a,
string  $b 
)
private

Performs a bitwise operation on a decimal number.

Paramètres
string$operatorThe operator to use, must be "and", "or" or "xor".
string$aThe left operand.
string$bThe right operand.
Renvoie
string

Références $b, $result, $value, Calculator\and(), elseif, Calculator\init(), Calculator\neg(), Calculator\or(), Calculator\toBinary(), Calculator\toDecimal(), Calculator\twosComplement(), et Calculator\xor().

Référencé par Calculator\and(), Calculator\or(), et Calculator\xor().

◆ cmp()

cmp ( string  $a,
string  $b 
)
final

Compares two numbers.

Paramètres
string$aThe first number.
string$bThe second number.
Renvoie
int [-1, 0, 1] If the first number is less than, equal to, or greater than the second number.

Références $b, $result, elseif, et Calculator\init().

Référencé par Calculator\divRound(), Calculator\modInverse(), et NativeCalculator\sqrt().

◆ detect()

static detect ( )
staticprivate

Returns the fastest available Calculator implementation.

Renvoie
Calculator

◆ divQ()

divQ ( string  $a,
string  $b 
)
abstract

Returns the quotient of the division of two numbers.

Paramètres
string$aThe dividend.
string$bThe divisor, must not be zero.
Renvoie
string The quotient.

Référencé par Calculator\gcdExtended().

◆ divQR()

divQR ( string  $a,
string  $b 
)
abstract

Returns the quotient and remainder of the division of two numbers.

Paramètres
string$aThe dividend.
string$bThe divisor, must not be zero.
Renvoie
string[] An array containing the quotient and remainder.

Référencé par Calculator\divRound(), Calculator\toArbitraryBase(), et Calculator\toBinary().

◆ divR()

divR ( string  $a,
string  $b 
)
abstract

Returns the remainder of the division of two numbers.

Paramètres
string$aThe dividend.
string$bThe divisor, must not be zero.
Renvoie
string The remainder.

Référencé par Calculator\gcd(), et Calculator\mod().

◆ divRound()

divRound ( string  $a,
string  $b,
int  $roundingMode 
)
final

Performs a rounded division.

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

Paramètres
string$aThe dividend.
string$bThe divisor.
int$roundingModeThe rounding mode.
Renvoie
string
Exceptions

Références $b, $r, Calculator\abs(), Calculator\add(), RoundingMode\CEILING, Calculator\cmp(), Calculator\divQR(), RoundingMode\DOWN, RoundingMode\FLOOR, RoundingMode\HALF_CEILING, RoundingMode\HALF_DOWN, RoundingMode\HALF_EVEN, RoundingMode\HALF_FLOOR, RoundingMode\HALF_UP, Calculator\mul(), RoundingNecessaryException\roundingNecessary(), RoundingMode\UNNECESSARY, et RoundingMode\UP.

◆ fromArbitraryBase()

fromArbitraryBase ( string  $number,
string  $alphabet,
int  $base 
)
final

Converts a non-negative number in an arbitrary base using a custom alphabet, to base 10.

Paramètres
string$numberThe number to convert, validated as a non-empty string, containing only chars in the given alphabet/base.
string$alphabetThe alphabet that contains every digit, validated as 2 chars minimum.
int$baseThe base of the number, validated from 2 to alphabet length.
Renvoie
string The number in base 10, following the Calculator conventions.

Références $base, $i, $result, Calculator\add(), et Calculator\mul().

Référencé par Calculator\fromBase().

◆ fromBase()

fromBase ( string  $number,
int  $base 
)

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ètres
string$numberThe number, positive or zero, non-empty, case-insensitively validated for the given base.
int$baseThe base of the number, validated from 2 to 36.
Renvoie
string The converted number, following the Calculator conventions.

Références $base, et Calculator\fromArbitraryBase().

◆ gcd()

gcd ( string  $a,
string  $b 
)

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ètres
string$aThe first number.
string$bThe second number.
Renvoie
string The GCD, always positive, or zero if both arguments are zero.

Références $b, Calculator\abs(), et Calculator\divR().

◆ gcdExtended()

gcdExtended ( string  $a,
string  $b,
string &  $x,
string &  $y 
)
private

◆ get()

◆ init()

init ( string  $a,
string  $b 
)
finalprotected

Extracts the sign & digits of the operands.

Paramètres
string$aThe first operand.
string$bThe second operand.
Renvoie
array{0: bool, 1: bool, 2: string, 3: string} Whether $a and $b are negative, followed by their digits.

Références $b.

Référencé par NativeCalculator\add(), Calculator\bitwise(), Calculator\cmp(), NativeCalculator\divQR(), et NativeCalculator\mul().

◆ mod()

mod ( string  $a,
string  $b 
)
Paramètres
string$a
string$bThe modulus; must not be zero.
Renvoie
string

Références $b, Calculator\add(), et Calculator\divR().

Référencé par Calculator\gcdExtended(), et Calculator\modInverse().

◆ modInverse()

modInverse ( string  $x,
string  $m 
)

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ètres
string$x
string$mThe modulus; must not be negative or zero.
Renvoie
string|null

Références $g, Calculator\abs(), Calculator\add(), Calculator\cmp(), Calculator\gcdExtended(), Calculator\mod(), et null.

◆ modPow()

modPow ( string  $base,
string  $exp,
string  $mod 
)
abstract

Raises a number into power with modulo.

Paramètres
string$baseThe base number; must be positive or zero.
string$expThe exponent; must be positive or zero.
string$modThe modulus; must be strictly positive.
Renvoie
string The power.

◆ mul()

mul ( string  $a,
string  $b 
)
abstract

Multiplies two numbers.

Paramètres
string$aThe multiplicand.
string$bThe multiplier.
Renvoie
string The product.

Référencé par Calculator\divRound(), Calculator\fromArbitraryBase(), Calculator\gcdExtended(), et Calculator\toDecimal().

◆ neg()

neg ( string  $n)
final

Negates a number.

Paramètres
string$nThe number.
Renvoie
string The negated value.

Références $n.

Référencé par NativeCalculator\add(), Calculator\bitwise(), NativeCalculator\divQR(), NativeCalculator\doSub(), NativeCalculator\mul(), et NativeCalculator\sub().

◆ or()

or ( string  $a,
string  $b 
)

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ètres
string$a
string$b
Renvoie
string

Références $b, et Calculator\bitwise().

Référencé par Calculator\bitwise().

◆ pow()

pow ( string  $a,
int  $e 
)
abstract

Exponentiates a number.

Paramètres
string$aThe base number.
int$eThe exponent, validated as an integer between 0 and MAX_POWER.
Renvoie
string The power.

◆ set()

static set ( ?Calculator  $calculator)
staticfinal

Sets the Calculator instance to use.

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

Paramètres
Calculator | null$calculatorThe calculator instance, or NULL to revert to autodetect.
Renvoie
void

◆ sqrt()

sqrt ( string  $n)
abstract

Returns the square root of the given number, rounded down.

The result is the largest x such that x² ≤ n. The input MUST NOT be negative.

Paramètres
string$nThe number.
Renvoie
string The square root.

◆ sub()

sub ( string  $a,
string  $b 
)
abstract

Subtracts two numbers.

Paramètres
string$aThe minuend.
string$bThe subtrahend.
Renvoie
string The difference.

Référencé par Calculator\gcdExtended().

◆ toArbitraryBase()

toArbitraryBase ( string  $number,
string  $alphabet,
int  $base 
)
final

Converts a non-negative number to an arbitrary base using a custom alphabet.

Paramètres
string$numberThe number to convert, positive or zero, following the Calculator conventions.
string$alphabetThe alphabet that contains every digit, validated as 2 chars minimum.
int$baseThe base to convert to, validated from 2 to alphabet length.
Renvoie
string The converted number in the given alphabet.

Références $base, $result, et Calculator\divQR().

Référencé par Calculator\toBase().

◆ toBase()

toBase ( string  $number,
int  $base 
)

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ètres
string$numberThe number to convert, following the Calculator conventions.
int$baseThe base to convert to, validated from 2 to 36.
Renvoie
string The converted number, lowercase.

Références $base, et Calculator\toArbitraryBase().

◆ toBinary()

toBinary ( string  $number)
private

Converts a decimal number to a binary string.

Paramètres
string$numberThe number to convert, positive or zero, only digits.
Renvoie
string

Références $result, et Calculator\divQR().

Référencé par Calculator\bitwise().

◆ toDecimal()

toDecimal ( string  $bytes)
private

Returns the positive decimal representation of a binary number.

Paramètres
string$bytesThe bytes representing the number.
Renvoie
string

Références $i, $result, Calculator\add(), et Calculator\mul().

Référencé par Calculator\bitwise().

◆ twosComplement()

twosComplement ( string  $number)
private
Paramètres
string$numberA positive, binary number.
Renvoie
string

Références $i.

Référencé par Calculator\bitwise().

◆ xor()

xor ( string  $a,
string  $b 
)

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ètres
string$a
string$b
Renvoie
string

Références $b, et Calculator\bitwise().

Référencé par Calculator\bitwise().

Documentation des champs

◆ $instance

$instance
staticprivate

◆ ALPHABET

const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz'

The alphabet for converting from and to base 2 to 36, lowercase.

Référencé par BigInteger\fromBase().

◆ MAX_POWER

const MAX_POWER = 1000000

The maximum exponent value allowed for the pow() method.

Référencé par BigDecimal\power(), et BigInteger\power().


La documentation de cette classe a été générée à partir du fichier suivant :