Libraries |
|
Bigint | Source Code |
|
|
Types | ||||
|
bigInteger
const type: bigInteger
-
Signed integer numbers of unlimited size. The literals of the type bigInteger are sequences of digits followed by an underscore character (for example 1_ ). Although bigInteger operations cannot overflow, it can happen that there is not enough memory to represent a bigInteger value. In this case the exception MEMORY_ERROR is raised.
Operator Summary | |||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
void |
| ||||
void |
| ||||
void |
| ||||
void |
| ||||
void |
| ||||
boolean |
| ||||
boolean |
| ||||
boolean |
| ||||
boolean |
| ||||
boolean |
| ||||
boolean |
| ||||
quotRem |
| ||||
bigInteger |
| ||||
string |
| ||||
string |
| ||||
bigInteger |
| ||||
string |
| ||||
bigInteger |
| ||||
bigInteger |
|
Function Summary | |||||
integer |
| ||||
integer |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
boolean |
| ||||
integer |
| ||||
integer |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
string |
| ||||
string |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
integer |
| ||||
integer |
| ||||
void |
| ||||
void |
| ||||
bigInteger |
| ||||
bigInteger |
| ||||
bigInteger |
|
Operator Detail |
+
const func bigInteger: + (in bigInteger: number)
-
Plus sign for bigInteger numbers.
- Returns:
- its operand unchanged.
-
const func bigInteger: - (in bigInteger: number)
-
Minus sign, negate a bigInteger number.
- Returns:
- the negated value of the number.
+
const func bigInteger: (in bigInteger: summand1) + (in bigInteger: summand2)
-
Add two bigInteger numbers.
- Returns:
- the sum of the two numbers.
-
const func bigInteger: (in bigInteger: minuend) - (in bigInteger: subtrahend)
-
Compute the subtraction of two bigInteger numbers.
- Returns:
- the difference of the two numbers.
*
const func bigInteger: (in bigInteger: factor1) * (in bigInteger: factor2)
-
Multiply two bigInteger numbers.
- Returns:
- the product of the two numbers.
div
const func bigInteger: (in bigInteger: dividend) div (in bigInteger: divisor)
-
Integer division truncated towards zero. The remainder of this division is computed with rem. For the operations div and rem holds for all A:
(A div B) * B + A rem B = A when B <> 0_ -A div B = -(A div B) when B <> 0_ -A rem B = -(A rem B) when B <> 0_ A rem B >= 0_ and A rem B < abs(B) when B <> 0_ and A >= 0_ A rem B <= 0_ and A rem B > -abs(B) when B <> 0_ and A <= 0_
- Returns:
- the quotient of the integer division.
- Raises:
- NUMERIC_ERROR - If a division by zero occurs.
rem
const func bigInteger: (in bigInteger: dividend) rem (in bigInteger: divisor)
-
Compute the remainder of the integer division div. The remainder has the same sign as the dividend.
A rem B
is equivalent to
A - (A div B) * B
- Returns:
- the remainder of the integer division.
- Raises:
- NUMERIC_ERROR - If a division by zero occurs.
mdiv
const func bigInteger: (in bigInteger: dividend) mdiv (in bigInteger: divisor)
-
Integer division truncated towards negative infinity. The modulo (remainder) of this division is computed with 'mod'. Therefore this division is called modulo division (mdiv). For the operations mdiv and mod holds for all A:
(A mdiv B) * B + A mod B = A when B <> 0_ -A mdiv B = A mdiv -B when B <> 0_ -A mod -B = -(A mod B) when B <> 0_ A mod B >= 0_ and A mod B < B when B > 0_ A mod B <= 0_ and A mod B > B when B < 0_
- Returns:
- the quotient of the integer division.
- Raises:
- NUMERIC_ERROR - If a division by zero occurs.
mod
const func bigInteger: (in bigInteger: dividend) mod (in bigInteger: divisor)
-
Compute the modulo (remainder) of the integer division mdiv. The modulo has the same sign as the divisor.
A mod B
is equivalent to
A - (A mdiv B) * B
- Returns:
- the modulo of the integer division.
- Raises:
- NUMERIC_ERROR - If a division by zero occurs.
**
const func bigInteger: (in bigInteger: base) ** (in integer: exponent)
-
Compute the exponentiation of a bigInteger base with an integer exponent.
A ** 0 returns 1_ for every A, even for A = 0_ 1 ** B returns 1_ for B >= 0 A ** B returns -(-A) ** B for A <= 0_ and B >= 0 and odd(B) A ** B returns (-A) ** B for A <= 0_ and B >= 0 and not odd(B)
- Returns:
- the result of the exponentiation.
- Raises:
- NUMERIC_ERROR - If the exponent is negative.
<<
const func bigInteger: (in bigInteger: number) << (in integer: lshift)
-
Shift a bigInteger number left by lshift bits. If lshift is negative a right shift is done instead. A << B is equivalent to A * 2_ ** B when B >= 0 holds. A << B is equivalent to A mdiv 2_ ** -B when B < 0 holds.
- Returns:
- the left shifted number.
>>
const func bigInteger: (in bigInteger: number) >> (in integer: rshift)
-
Shift a bigInteger number right by rshift bits. If rshift is negative a left shift is done instead. A >> B is equivalent to A mdiv 2_ ** B when B >= 0 holds. A >> B is equivalent to A * 2_ ** -B when B < 0 holds.
- Returns:
- the right shifted number.
+:=
const proc: (inout bigInteger: number) +:= (in bigInteger: delta)
-
Increment a bigInteger variable by a delta.
-:=
const proc: (inout bigInteger: number) -:= (in bigInteger: delta)
-
Decrement a bigInteger variable by a delta.
*:=
const proc: (inout bigInteger: number) *:= (in bigInteger: factor)
-
Multiply a bigInteger number by a factor and assign the result back to number.
<<:=
const proc: (inout bigInteger: number) <<:= (in integer: lshift)
-
Shift a number left by lshift bits and assign the result back to number. If lshift is negative a right shift is done instead.
>>:=
const proc: (inout bigInteger: number) >>:= (in integer: rshift)
-
Shift a number right by rshift bits and assign the result back to number. If rshift is negative a left shift is done instead.
=
const func boolean: (in bigInteger: number1) = (in bigInteger: number2)
-
Check if two bigInteger numbers are equal.
- Returns:
- TRUE if both numbers are equal, FALSE otherwise.
<>
const func boolean: (in bigInteger: number1) <> (in bigInteger: number2)
-
Check if two bigInteger numbers are not equal.
- Returns:
- FALSE if both numbers are equal, TRUE otherwise.
<
const func boolean: (in bigInteger: number1) < (in bigInteger: number2)
-
Check if number1 is less than number2.
- Returns:
- TRUE if number1 is less than number2, FALSE otherwise.
>
const func boolean: (in bigInteger: number1) > (in bigInteger: number2)
-
Check if number1 is greater than number2.
- Returns:
- TRUE if number1 is greater than number2, FALSE otherwise.
<=
const func boolean: (in bigInteger: number1) <= (in bigInteger: number2)
-
Check if number1 is less than or equal to number2.
- Returns:
- TRUE if number1 is less than or equal to number2, FALSE otherwise.
>=
const func boolean: (in bigInteger: number1) >= (in bigInteger: number2)
-
Check if number1 is greater than or equal to number2.
- Returns:
- TRUE if number1 is greater than or equal to number2, FALSE otherwise.
divRem
const func quotRem: (in bigInteger: dividend) divRem (in bigInteger: divisor)
-
Quotient and remainder of integer division truncated towards zero. Compute quotient and remainder of the integer division div.
- Returns:
- quotRem with quotient and remainder of the integer division.
- Raises:
- NUMERIC_ERROR - If a division by zero occurs.
conv
const func bigInteger: (attr bigInteger) conv (in integer: number)
-
Convert an integer number to bigInteger.
- Returns:
- the bigInteger result of the conversion.
- Raises:
- MEMORY_ERROR - Not enough memory to represent the result.
radix
const func string: (in var bigInteger: number) radix (in integer: base)
-
Convert a bigInteger number to a string using a radix. The conversion uses the numeral system with the given base. Digit values from 10 upward are encoded with lower case letters. E.g.: 10 is encoded with a, 11 with b, etc. For negative numbers a minus sign is prepended.
3735928559_ radix 16 => "deadbeef" -3735928559_ radix 16 => "-deadbeef"
- Returns:
- the string result of the conversion.
- Raises:
- RANGE_ERROR - If base < 2 or base > 36 holds.
- MEMORY_ERROR - Not enough memory to represent the result.
RADIX
const func string: (in var bigInteger: number) RADIX (in integer: base)
-
Convert a bigInteger number to a string using a radix. The conversion uses the numeral system with the given base. Digit values from 10 upward are encoded with upper case letters. E.g.: 10 is encoded with A, 11 with B, etc. For negative numbers a minus sign is prepended.
3735928559_ RADIX 16 => "DEADBEEF" -3735928559_ RADIX 16 => "-DEADBEEF"
- Returns:
- the string result of the conversion.
- Raises:
- RANGE_ERROR - If base < 2 or base > 36 holds.
- MEMORY_ERROR - Not enough memory to represent the result.
parse
const func bigInteger: (attr bigInteger) parse (in string: stri)
-
Convert a string to a bigInteger number. The string must contain an integer literal consisting of an optional + or - sign, followed by a sequence of digits. Other characters as well as leading or trailing whitespace characters are not allowed. The sequence of digits is taken to be decimal.
bigInteger parse "12345" returns 12345_ bigInteger parse "-12345" returns -12345_ bigInteger parse "+12345" returns 12345_ bigInteger parse " 12345" raises RANGE_ERROR bigInteger parse "12345 " raises RANGE_ERROR bigInteger parse "-" raises RANGE_ERROR bigInteger parse "zero" raises RANGE_ERROR bigInteger parse "9223372036854775807" returns 9223372036854775807_ bigInteger parse "9223372036854775808" returns 9223372036854775808_
- Returns:
- the bigInteger result of the conversion.
- Raises:
- RANGE_ERROR - If the string is empty or it does not contain an integer literal.
- MEMORY_ERROR - Not enough memory to represent the result.
sci
const func string: (in bigInteger: number) sci (in integer: precision)
-
Convert a bigInteger number to a string in scientific notation. Scientific notation uses a decimal significand and a decimal exponent. The significand has an optional sign and exactly one digit before the decimal point. The fractional part of the significand is rounded to the specified number of digits (precision). Halfway cases are rounded away from zero. The fractional part is followed by the letter e and an exponent, which is always signed. The value zero is never written with a negative sign.
12345_ sci 4 returns "1.2345e+4" 12345_ sci 3 returns "1.235e+4" 12345_ sci 2 returns "1.23e+4" 3141592_ sci 0 returns "3e+6" 27182818_ sci 0 returns "3e+7" 2_**64 sci 6 returns "1.844674e+19" -1_ sci 3 returns "-1.000e+0" -0_ sci 2 returns "0.00e+0"
- Parameters:
- precision - Number of digits after the decimal point. If the precision is zero the decimal point is omitted.
- Returns:
- the string result of the conversion.
- Raises:
- RANGE_ERROR - If the precision is negative.
!
const func bigInteger: ! (in bigInteger: number)
-
Compute the factorial of a bigInteger number.
- Returns:
- the factorial of the number.
- Raises:
- NUMERIC_ERROR - The number is negative.
!
const func bigInteger: (in bigInteger: n) ! (in var bigInteger: k)
-
Compute the binomial coefficient
n ! k returns 0 for k < 0, n ! 0_ returns 1_, n ! 1_ returns n, n ! k returns 0 for n >= 0 and k > n, n ! k returns !n div (!k * !(n - k)) for k >= 0 and k <= n, n ! k returns (-1) ** k * (n + k - 1 ! k) for n < 0 and k >= 0
- Returns:
- n over k
Function Detail |
compare
const func integer: compare (in bigInteger: number1, in bigInteger:number2)
-
Compare two bigInteger numbers.
- Returns:
- -1, 0 or 1 if the first argument is considered to be respectively less than, equal to, or greater than the second.
hashCode
const func integer: hashCode (in bigInteger: number)
-
Compute the hash value of a bigInteger number.
- Returns:
- the hash value.
succ
const func bigInteger: succ (in bigInteger: number)
-
Successor of a bigInteger number. succ(A) is equivalent to A+1 .
- Returns:
- number + 1 .
pred
const func bigInteger: pred (in bigInteger: number)
-
Predecessor of a bigInteger number. pred(A) is equivalent to A-1 .
- Returns:
- number - 1 .
abs
const func bigInteger: abs (in bigInteger: number)
-
Compute the absolute value of a bigInteger number.
- Returns:
- the absolute value.
log10
const func bigInteger: log10 (in bigInteger: number)
-
Compute the truncated base 10 logarithm of a bigInteger number. The definition of log10 is extended by defining log10(0_) = -1_.
log10(10_ ** A) returns A for A >= 0 log10(pred(10_ ** A)) returns pred(A) for A >= 0 log10(10_) returns 1 log10(1_) returns 0 log10(0_) returns -1
- Returns:
- the truncated base 10 logarithm.
- Raises:
- NUMERIC_ERROR - The number is negative.
log2
const func bigInteger: log2 (in bigInteger: number)
-
Compute the truncated base 2 logarithm of a bigInteger number. The definition of log2 is extended by defining log2(0_) = -1_.
log2(2_ ** A) returns A for A >= 0 log2(pred(2_ ** A)) returns pred(A) for A >= 0 log2(2_) returns 1 log2(1_) returns 0 log2(0_) returns -1
- Returns:
- the truncated base 2 logarithm.
- Raises:
- NUMERIC_ERROR - The number is negative.
odd
const func boolean: odd (in bigInteger: number)
-
Determine if a bigInteger number is odd.
- Returns:
- TRUE if the number is odd, FALSE otherwise.
ord
const func integer: ord (in bigInteger: number)
integer
const func integer: integer (in bigInteger: number)
gcd
const func bigInteger: gcd (in bigInteger: number1, in bigInteger: number2)
-
Compute the greatest common divisor of two bigInteger numbers.
- Returns:
- the greatest common divisor of the two numbers. The greatest common divisor is positive or zero.
bigInteger
const func bigInteger: bigInteger (in integer: number)
-
Convert an integer number to bigInteger.
- Returns:
- the bigInteger result of the conversion.
- Raises:
- MEMORY_ERROR - Not enough memory to represent the result.
str
const func string: str (in bigInteger: number)
-
Convert a bigInteger number to a string. The number is converted to a string with decimal representation. For negative numbers a minus sign is prepended.
- Returns:
- the string result of the conversion.
- Raises:
- MEMORY_ERROR - Not enough memory to represent the result.
literal
const func string: literal (in bigInteger: number)
-
Convert a bigInteger number to a bigInteger literal.
- Returns:
- the bigInteger literal.
- Raises:
- MEMORY_ERROR - Not enough memory to represent the result.
bigInteger
const func bigInteger: bigInteger (in string: stri)
-
Convert a string to a bigInteger number. The string must contain an integer literal consisting of an optional + or - sign, followed by a sequence of digits. Other characters as well as leading or trailing whitespace characters are not allowed. The sequence of digits is taken to be decimal.
bigInteger("12345") returns 12345_ bigInteger("-12345") returns -12345_ bigInteger("+12345") returns 12345_ bigInteger(" 12345") raises RANGE_ERROR bigInteger("12345 ") raises RANGE_ERROR bigInteger("-") raises RANGE_ERROR bigInteger("zero") raises RANGE_ERROR bigInteger("9223372036854775807") returns 9223372036854775807_ bigInteger("9223372036854775808") returns 9223372036854775808_
- Returns:
- the bigInteger result of the conversion.
- Raises:
- RANGE_ERROR - If the string is empty or it does not contain an integer literal.
- MEMORY_ERROR - Not enough memory to represent the result.
bigInteger
const func bigInteger: bigInteger (in string: stri, in integer: base)
-
Convert a numeric string, with a specified radix, to a bigInteger. The numeric string must contain the representation of an integer in the specified radix. It consists of an optional + or - sign, followed by a sequence of digits in the specified radix. Digit values from 10 upward can be encoded with upper or lower case letters. E.g.: 10 can be encoded with A or a, 11 with B or b, etc. Other characters as well as leading or trailing whitespace characters are not allowed.
bigInteger("deadbeef", 16) returns 3735928559_ bigInteger("-77777777777", 8) returns -8589934591_ bigInteger("10101010", 2) returns 170_ bigInteger("Cafe", 16) returns 51966_
- Parameters:
- base - Radix of the integer in the stri parameter.
- Returns:
- the bigInteger result of the conversion.
- Raises:
- RANGE_ERROR - If base < 2 or base > 36 holds or the string is empty or it does not contain an integer literal with the specified base.
- MEMORY_ERROR - Not enough memory to represent the result.
rand
const func bigInteger: rand (in bigInteger: low, in bigInteger: high)
-
Compute pseudo-random number in the range [low, high]. The random values are uniform distributed.
- Returns:
- a random number such that low <= rand(low, high) and rand(low, high) <= high holds.
- Raises:
- RANGE_ERROR - The range is empty (low > high holds).
bitLength
const func integer: bitLength (in bigInteger: number)
-
Number of bits in the minimum two's-complement representation. The high bits equivalent to the sign bit are not part of the minimum two's-complement representation.
bitLength(0_) returns 0 bitLength(1_) returns 1 bitLength(4_) returns 3 bitLength(-1_) returns 0 bitLength(-2_) returns 1 bitLength(-4_) returns 2
- Returns:
- the number of bits.
- Raises:
- RANGE_ERROR - The result does not fit into an integer.
lowestSetBit
const func integer: lowestSetBit (in bigInteger: number)
-
Number of lowest-order zero bits in the two's-complement representation. This is equal to the index of the lowest-order one bit (indices start with 0). If there are only zero bits (number is 0_) the result is -1.
lowestSetBit(0_) returns -1 lowestSetBit(1_) returns 0 lowestSetBit(4_) returns 2 lowestSetBit(-1_) returns 0 lowestSetBit(-2_) returns 1 lowestSetBit(-4_) returns 2
- Returns:
- the number of lowest-order zero bits or -1 for lowestSetBit(0_).
incr
const proc: incr (inout bigInteger: number)
-
Increment a bigInteger variable. Increments number by 1. This is equivalent to:
number := succ(number);
decr
const proc: decr (inout bigInteger: number)
-
Decrement a bigInteger variable. Decrements number by 1. This is equivalent to:
number := pred(number);
sqrt
const func bigInteger: sqrt (in var bigInteger: number)
-
Compute the integer square root of a bigInteger number.
- Returns:
- the integer square root.
- Raises:
- NUMERIC_ERROR - If number is negative.
modInverse
const func bigInteger: modInverse (in var bigInteger: a, in var bigInteger: b)
-
Compute the modular multiplicative inverse of a modulo b.
- Returns:
- the modular multiplicative inverse when a and b are coprime (gcd(a, b) = 1).
- Raises:
- RANGE_ERROR - If a and b are not coprime (gcd(a, b) <> 1).
modPow
const func bigInteger: modPow (in var bigInteger: base, in var bigInteger: exponent, in bigInteger: modulus)
-
Compute the modular exponentiation of base ** exponent.
- Returns:
- base ** exponent mod modulus
- Raises:
- RANGE_ERROR - If exponent or modulus are negative.
|
|