[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

An arbitrary-size integer. All methods accepting a number as a parameter accept either a BigInteger instance, an integer, or a string representing an arbitrary size integer.

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

Defines 51 functions

  __construct()
  of()
  parse()
  fromBase()
  fromArbitraryBase()
  fromBytes()
  randomBits()
  randomRange()
  zero()
  one()
  ten()
  plus()
  minus()
  multipliedBy()
  dividedBy()
  power()
  quotient()
  remainder()
  quotientAndRemainder()
  mod()
  modInverse()
  modPow()
  powerMod()
  gcd()
  sqrt()
  abs()
  negated()
  and()
  or()
  xor()
  shiftedLeft()
  shiftedRight()
  getBitLength()
  getLowestSetBit()
  isEven()
  isOdd()
  testBit()
  compareTo()
  getSign()
  toBigInteger()
  toBigDecimal()
  toBigRational()
  toScale()
  toInt()
  toFloat()
  toBase()
  toArbitraryBase()
  toBytes()
  __toString()
  serialize()
  unserialize()

Functions
Functions that are not part of a class:

__construct(string $value)   X-Ref
Protected constructor. Use a factory method to obtain an instance.

param: string $value A string of digits, with optional leading minus sign.

of($value)   X-Ref
Creates a BigInteger of the given value.

param: BigNumber|int|float|string $value
return: BigInteger

parse(string $number, int $base = 10)   X-Ref
Parses a string containing an integer in an arbitrary base.

param: string $number The number to parse.
param: int    $base   The base of the number, between 2 and 36.
return: BigInteger

fromBase(string $number, int $base)   X-Ref
Creates a number from a string in a given base.

The string can optionally be prefixed with the `+` or `-` sign.

Bases greater than 36 are not supported by this method, as there is no clear consensus on which of the lowercase
or uppercase characters should come first. Instead, this method accepts any base up to 36, and does not
differentiate lowercase and uppercase characters, which are considered equal.

For bases greater than 36, and/or custom alphabets, use the fromArbitraryBase() method.

param: string $number The number to convert, in the given base.
param: int    $base   The base of the number, between 2 and 36.
return: BigInteger

fromArbitraryBase(string $number, string $alphabet)   X-Ref
Parses a string containing an integer in an arbitrary base, using a custom alphabet.

Because this method accepts an alphabet with any character, including dash, it does not handle negative numbers.

param: string $number   The number to parse.
param: string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8.
return: BigInteger

fromBytes(string $value, bool $signed = true)   X-Ref
Translates a string of bytes containing the binary representation of a BigInteger into a BigInteger.

The input string is assumed to be in big-endian byte-order: the most significant byte is in the zeroth element.

If `$signed` is true, the input is assumed to be in two's-complement representation, and the leading bit is
interpreted as a sign bit. If `$signed` is false, the input is interpreted as an unsigned number, and the
resulting BigInteger will always be positive or zero.

This method can be used to retrieve a number exported by `toBytes()`, as long as the `$signed` flags match.

param: string $value  The byte string.
param: bool   $signed Whether to interpret as a signed number in two's-complement representation with a leading
return: BigInteger

randomBits(int $numBits, ?callable $randomBytesGenerator = null)   X-Ref
Generates a pseudo-random number in the range 0 to 2^numBits - 1.

Using the default random bytes generator, this method is suitable for cryptographic use.

param: int           $numBits              The number of bits.
param: callable|null $randomBytesGenerator A function that accepts a number of bytes as an integer, and returns a
return: BigInteger

randomRange($min, $max, ?callable $randomBytesGenerator = null)   X-Ref
Generates a pseudo-random number between `$min` and `$max`.

Using the default random bytes generator, this method is suitable for cryptographic use.

param: BigNumber|int|float|string $min                  The lower bound. Must be convertible to a BigInteger.
param: BigNumber|int|float|string $max                  The upper bound. Must be convertible to a BigInteger.
param: callable|null              $randomBytesGenerator A function that accepts a number of bytes as an integer,
return: BigInteger

zero()   X-Ref
Returns a BigInteger representing zero.

return: BigInteger

one()   X-Ref
Returns a BigInteger representing one.

return: BigInteger

ten()   X-Ref
Returns a BigInteger representing ten.

return: BigInteger

plus($that)   X-Ref
Returns the sum of this number and the given one.

param: BigNumber|int|float|string $that The number to add. Must be convertible to a BigInteger.
return: BigInteger The result.

minus($that)   X-Ref
Returns the difference of this number and the given one.

param: BigNumber|int|float|string $that The number to subtract. Must be convertible to a BigInteger.
return: BigInteger The result.

multipliedBy($that)   X-Ref
Returns the product of this number and the given one.

param: BigNumber|int|float|string $that The multiplier. Must be convertible to a BigInteger.
return: BigInteger The result.

dividedBy($that, int $roundingMode = RoundingMode::UNNECESSARY)   X-Ref
Returns the result of the division of this number by the given one.

param: BigNumber|int|float|string $that         The divisor. Must be convertible to a BigInteger.
param: int                        $roundingMode An optional rounding mode.
return: BigInteger The result.

power(int $exponent)   X-Ref
Returns this number exponentiated to the given value.

param: int $exponent The exponent.
return: BigInteger The result.

quotient($that)   X-Ref
Returns the quotient of the division of this number by the given one.

param: BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger.
return: BigInteger

remainder($that)   X-Ref
Returns the remainder of the division of this number by the given one.

The remainder, when non-zero, has the same sign as the dividend.

param: BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger.
return: BigInteger

quotientAndRemainder($that)   X-Ref
Returns the quotient and remainder of the division of this number by the given one.

param: BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger.
return: BigInteger[] An array containing the quotient and the remainder.

mod($that)   X-Ref
Returns the modulo of this number and the given one.

The modulo operation yields the same result as the remainder operation when both operands are of the same sign,
and may differ when signs are different.

The result of the modulo operation, when non-zero, has the same sign as the divisor.

param: BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger.
return: BigInteger

modInverse(BigInteger $m)   X-Ref
Returns the modular multiplicative inverse of this BigInteger modulo $m.

param: BigInteger $m
return: BigInteger

modPow($exp, $mod)   X-Ref
Returns this number raised into power with modulo.

This operation only works on positive numbers.

param: BigNumber|int|float|string $exp The positive exponent.
param: BigNumber|int|float|string $mod The modulus. Must not be zero.
return: BigInteger

powerMod($exp, $mod)   X-Ref
Returns this number raised into power with modulo.

param: BigNumber|int|float|string $exp The positive exponent.
param: BigNumber|int|float|string $mod The modulus. Must not be zero.
return: BigInteger

gcd($that)   X-Ref
Returns the greatest common divisor of this number and the given one.

The GCD is always positive, unless both operands are zero, in which case it is zero.

param: BigNumber|int|float|string $that The operand. Must be convertible to an integer number.
return: BigInteger

sqrt()   X-Ref
Returns the integer square root number of this number, rounded down.

The result is the largest x such that x² ≤ n.

return: BigInteger

abs()   X-Ref
Returns the absolute value of this number.

return: BigInteger

negated()   X-Ref
Returns the inverse of this number.

return: BigInteger

and($that)   X-Ref
Returns the integer bitwise-and combined with another integer.

This method returns a negative BigInteger if and only if both operands are negative.

param: BigNumber|int|float|string $that The operand. Must be convertible to an integer number.
return: BigInteger

or($that)   X-Ref
Returns the integer bitwise-or combined with another integer.

This method returns a negative BigInteger if and only if either of the operands is negative.

param: BigNumber|int|float|string $that The operand. Must be convertible to an integer number.
return: BigInteger

xor($that)   X-Ref
Returns the integer bitwise-xor combined with another integer.

This method returns a negative BigInteger if and only if exactly one of the operands is negative.

param: BigNumber|int|float|string $that The operand. Must be convertible to an integer number.
return: BigInteger

shiftedLeft(int $distance)   X-Ref
Returns the integer left shifted by a given number of bits.

param: int $distance The distance to shift.
return: BigInteger

shiftedRight(int $distance)   X-Ref
Returns the integer right shifted by a given number of bits.

param: int $distance The distance to shift.
return: BigInteger

getBitLength()   X-Ref
Returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit.

For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation.
Computes (ceil(log2(this < 0 ? -this : this+1))).

return: int

getLowestSetBit()   X-Ref
Returns the index of the rightmost (lowest-order) one bit in this BigInteger.

Returns -1 if this BigInteger contains no one bits.

return: int

isEven()   X-Ref
Returns whether this number is even.

return: bool

isOdd()   X-Ref
Returns whether this number is odd.

return: bool

testBit(int $n)   X-Ref
Returns true if and only if the designated bit is set.

Computes ((this & (1<<n)) != 0).

param: int $n The bit to test, 0-based.
return: bool

compareTo($that)   X-Ref
{@inheritdoc}


getSign()   X-Ref
{@inheritdoc}


toBigInteger()   X-Ref
{@inheritdoc}


toBigDecimal()   X-Ref
{@inheritdoc}


toBigRational()   X-Ref
{@inheritdoc}


toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY)   X-Ref
{@inheritdoc}


toInt()   X-Ref
{@inheritdoc}


toFloat()   X-Ref
{@inheritdoc}


toBase(int $base)   X-Ref
Returns a string representation of this number in the given base.

The output will always be lowercase for bases greater than 10.

param: int $base
return: string

toArbitraryBase(string $alphabet)   X-Ref
Returns a string representation of this number in an arbitrary base with a custom alphabet.

Because this method accepts an alphabet with any character, including dash, it does not handle negative numbers;
a NegativeNumberException will be thrown when attempting to call this method on a negative number.

param: string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8.
return: string

toBytes(bool $signed = true)   X-Ref
Returns a string of bytes containing the binary representation of this BigInteger.

The string is in big-endian byte-order: the most significant byte is in the zeroth element.

If `$signed` is true, the output will be in two's-complement representation, and a sign bit will be prepended to
the output. If `$signed` is false, no sign bit will be prepended, and this method will throw an exception if the
number is negative.

The string will contain the minimum number of bytes required to represent this BigInteger, including a sign bit
if `$signed` is true.

This representation is compatible with the `fromBytes()` factory method, as long as the `$signed` flags match.

param: bool $signed Whether to output a signed number in two's-complement representation with a leading sign bit.
return: string

__toString()   X-Ref
{@inheritdoc}


serialize()   X-Ref
This method is required by interface Serializable and SHOULD NOT be accessed directly.

return: string

unserialize($value)   X-Ref
This method is only here to implement interface Serializable and cannot be accessed directly.

param: string $value
return: void



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