Press on the image to return to the main documentation page. |

BigInteger

accuracy is required, the classic example being financial computations where the intrinsic

approximations of Floats and Doubles to exact decimal values are unaccetable.

A BigDecimal consists of an arbitrary precision integer unscaled value, which is actually a

BigInteger, and a 32-bit integer scale. If zero or positive, the scale is the number of digits

to the right of the decimal point. If negative, the unscaled value of the number is multiplied by

ten to the power of the negation of the scale. The value of the number represented by the BigDecimal

is therefore (unscaledValue × 10-scale).

Note that the various Initializers do not offer initialization from Floats or Doubles.

This is a deliberate design choice as Floats and Doubles are inaccurate representations of most decimal values.

For example FloatVar = 0.1 will cause FloatVar to actually contain a value slightly larger than 0.1.

Also note that where a numeric unquoted literal is used in code as a parameter to Initialize

Basic4android converts it first to a Double and so a slightly inaccurate value may result.

Many of the operations return the BigDecimal itself so allowing operations to be chained.

For example "BigD1.Add(BigD2).Multiply(BigD3)". Such expressions are evaluated left to right.

The Java documentation should be studied for more information on BigDecimal.

Note that the Class Overview in the Android online documentation is incorrect and actually applies to

BigInteger, not BigDecimal.

The scale of the result is the same as the original scale of this.

Returns itself.

Returns itself.

The method behaves as if this.subtract(val) is computed.

If this difference is > 0 then 1 is returned, if the difference is < 0 then -1 is returned,

and if the difference is 0 then 0 is returned.

This means, that if two decimal instances are compared which are equal in value but differ in scale,

then these two instances are considered as equal unlike Equals().

The scale of the result is the difference of the scales of this and divisor.

If the exact result requires more digits, then the scale is adjusted accordingly.

For example, 1/128 = 0.0078125 which has a scale of 7 and precision 5.

Throws an ArithmeticException if the result cannot be represented exactly

because it has a non-terminating decimal expansion.

Returns itself.

The result is rounded according to the passed parameters.

If the passed precision is 0, then this call is equivalent to Divide(divisor).

Returns itself.

The quotient is rounded down towards zero to the next integer. For example, 0.5/0.2 = 2.

then Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY is returned.

Note that many BigDecimal values, such as 0.1, cannot be represented accurately by a Double.

Beware of using unquoted literals as parameters as they will be first converted to Double.

The array may contain the characters 0 to 9 and a decimal point.

The most significant digit of the number is at index 0 in the array.

The scale of the result is scale, and its unscaled value is unscaledVal.

The scale of the BigDecimal is zero.

If the integral part of this is too big to be represented as an long, then this % 2^64 is returned.

Returns itself.

Returns itself

If n < 0 then the decimal point is moved -n places to the right.

The result is obtained by changing its scale. If the scale of the result becomes negative,

then its precision is increased such that the scale is zero.

Returns itself.

If n < 0 then the decimal point is moved -n places to the left.

The result is obtained by changing its scale. If the scale of the result becomes negative,

then its precision is increased such that the scale is zero.

Returns itself.

The scale of the result is the sum of the scales of the two arguments.

Returns itself.

The scale of the result is the same as the scale of this.

Returns itself

The scale of the result is the same as the scale of this.

Returns itself.

The scale of the result is n times the scales of this.

Returns itself.

The precision is the number of decimal digits used to represent this decimal.

It is equivalent to the number of digits of the unscaled value.

The precision of 0 is 1 (independent of the scale).

Returns itself.

and ROUND_XXX type.

If precision = 0, then no rounding is performed.

If precision > 0 and = ROUND_UNNECESSARY, then an ArithmeticException is thrown if the result

cannot be represented exactly within the given precision.

Returns itself.

For positive values this rounding mode behaves as ROUND_UP,

for negative values as ROUND_DOWN.

For positive values this rounding mode behaves as ROUND_DOWN,

for negative values as ROUND_UP.

Ties are broken by rounding down.

Ties are broken by rounding to the even neighbor.

Ties are broken by rounding up.

that rounding is necessary, i.e. for the case that the value cannot be represented exactly.

and negative values towards negative infinity.

The scale is the number of digits behind the decimal point.

The value of this BigDecimal is the unsignedValue * 10^(-scale).

If the scale is negative, then this BigDecimal represents a big integer.

The scale of the result is this.scale() - n.

The precision of the result is the precision of this.

This method has the same effect as movePointRight(int), except that the precision is not changed.

Returns itself.

If the new scale is greater than the old scale, then additional zeros are added to the unscaled value.

If the new scale is smaller than the old scale, then trailing zeros are removed.

If the trailing digits are not zeros then an ArithmeticException is thrown.

If no exception is thrown, then the following equation holds: x.setScale(s).compareTo(x) = 0.

Returns itself.

Returns itself.

If the new scale is greater than the old scale, then additional zeros are added to the unscaled value.

In this case no rounding is necessary.

If the new scale is smaller than the old scale, then trailing digits are removed.

If these trailing digits are not zero, then the remaining unscaled value has to be rounded.

For this rounding operation the specified rounding mode is used.

if rounding = ROUND_UNNECESSARY and rounding is necessary according to the given scale then

an ArithmeticException is thrown.

where the trailing zeros have been removed.

If the unscaled value of this has n trailing zeros, then the scale and the precision

of the result has been reduced by n.

Returns itself.

The scale of the result is the maximum of the scales of the two arguments.

Returns itself.

This representation always prints all significant digits of this value.

If the scale is negative or if scale - precision >= 6 then engineering notation is used.

Engineering notation is similar to the scientific notation except that the exponent is

made to be a multiple of 3 such that the integer part is >= 1 and < 1000.

This methods adds zeros where necessary.

If this string representation is used to create a new instance, this instance is

generally not identical to this as the precision changes.

The unscaled value can be computed as this * 10^(scale).

This implementation is efficient for operations traditionally used in cryptography,

such as the generation of large prime numbers and computation of the modular inverse.

This API includes operations for bitwise operations in two's complement representation.

Two's complement is not the internal representation used by this implementation, so such

methods may be inefficient.

Many of the operations return the BigInteger itself so allowing operations to be chained.

For example "BigI1.Add(BigI2).Multiply(BigI3)". Such expressions are evaluated left to right.

The Java documentation should be studied for more information on BigInteger.

Returns itself.

Returns itself.

Usage of this method is not recommended as the current implementation is not efficient.

Returns itself.

Usage of this method is not recommended as the current implementation is not efficient.

Returns itself.

from the sign bit. If this is negative, the result is equivalent to the number of bits

set in the two's complement representation of -this - 1.

Use bitLength() to find the length of the binary value in bits.

positive numbers / without leading ones for negative values.

The two's complement representation of this will be at least bitLength() + 1 bits long.

The value will fit into an int if bitLength() < 32 or into a long if bitLength() < 64.

the bit at position n cleared. The result is equivalent to this AND NOT(pow(2, n)).

Returns itself.

and 1 if this > value.

Returns itself.

then Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY is returned.

Note that not all integers in the range [-Double.MAX_VALUE, Double.MAX_VALUE] can be

exactly represented as a double.

the bit at position n flipped. The result is equivalent to this ^ pow(2, n).

Returns itself.

this BigInteger. If all bits are zero (this==0) then -1 is returned as result.

Beware of using unquoted literals as parameters as they will be first converted to Double.

The most significant digits of the number are at index 0 in the array.

[0, pow(2, bitLength)-1].

[0, pow(2, bitLength)-1] which is probably prime.

The probability that the returned BigInteger is prime is beyond 1 - 1/pow(2, certainty).

The scale of the BigDecimal is zero.

If this is too big to be represented as a long, then this % pow(2, 64) is returned.

RTturns itself.

Returns itself.

Returns itself.

The result is guaranteed to be in the interval [0, m] (0 inclusive, m exclusive).

The behavior of this function is not equivalent to the behavior of the % operator

defined for the built-in int's.

Returns itself.

The result is guaranteed to be in the interval [0, m] (0 inclusive, m exclusive).

If this is not relatively prime to m, then an exception is thrown.

Returns itself.

The result is guaranteed to be in the interval [0, m] (0 inclusive, m exclusive).

If the exponent is negative, then pow(this.modInverse(m), -exponent) mod m is computed.

The inverse of this only exists if this is relatively prime to m, otherwise an exception is thrown.

Returns itself.

Returns itself.

The probability that the returned BigInteger is prime is beyond 1 - 1/pow(2, 80).

Returns itself.

Returns itself.

Returns itself.

Returns itself.

which is probably prime.

The probability that the returned BigInteger is prime is beyond 1 - 1/pow(2, 80).

Returns itself.

Regarding signs this methods has the same behavior as the % operator on ints:

The sign of the remainder is the same as the sign of this.

Returns itself.

but with the bit at position n set. The result is equivalent to this | pow(2, n).

Returns itself.

The result is equivalent to this * pow(2, n) if n >= 0.

The shift distance may be negative which means that this is shifted right.

The result then corresponds to floor(this / pow(2, -n)).

Returns itself;

For negative arguments, the result is also negative.

The shift distance may be negative which means that this is shifted left.

Returns itself.

Returns itself.

The result is equivalent to this & pow(2, n) != 0.

Returns itself.

Top