Package totalcross.util
Class BigInteger
- java.lang.Object
-
- totalcross.util.BigInteger
-
- All Implemented Interfaces:
Comparable
public class BigInteger extends java.lang.Object implements Comparable
Written using on-line Java Platform 1.2 API Specification, as well as "The Java class libraries", 2nd edition (Addison-Wesley, 1998) and "Applied Cryptography, Second Edition" by Bruce Schneier (Wiley, 1996). Based primarily on IntNum.java BitOps.java by Per Bothner (per@bothner.com) (found in Kawa 1.6.62).
-
-
Field Summary
Fields Modifier and Type Field Description static BigIntegerONEThe constant one as a BigInteger.static BigIntegerTENThe constant ten as a BigInteger.static BigIntegerZEROThe constant zero as a BigInteger.
-
Constructor Summary
Constructors Constructor Description BigInteger(byte[] val)BigInteger(int signum, byte[] magnitude)BigInteger(int bitLength, int certainty, Random rnd)BigInteger(int numBits, Random rnd)BigInteger(java.lang.String val)BigInteger(java.lang.String s, int radix)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BigIntegerabs()BigIntegeradd(BigInteger val)BigIntegerand(BigInteger y)Return the logical (bit-wise) "and" of two BigIntegers.BigIntegerandNot(BigInteger val)intbitCount()Count one bits in a BigInteger.intbitLength()Calculates ceiling(log2(this < 0 ? -this : this+1)) See Common Lisp: the Language, 2nd ed, p.BigIntegerclearBit(int n)intcompareTo(java.lang.Object other)Must return > 0 if this object is greater than the other one, < 0 if its smaller, and 0 if they are equal.intcompareTo(BigInteger val)BigIntegerdivide(BigInteger val)BigInteger[]divideAndRemainder(BigInteger val)doubledoubleValue()booleanequals(java.lang.Object obj)BigIntegerflipBit(int n)BigIntegergcd(BigInteger y)intgetLowestSetBit()inthashCode()intintValue()booleanisProbablePrime(int certainty)Returnstrueif this BigInteger is probably prime,falseif it's definitely composite.longlongValue()BigIntegermax(BigInteger val)BigIntegermin(BigInteger val)BigIntegermod(BigInteger m)BigIntegermodInverse(BigInteger y)BigIntegermodPow(BigInteger exponent, BigInteger m)BigIntegermultiply(BigInteger y)BigIntegernegate()BigIntegernot()Return the logical (bit-wise) negation of a BigInteger.BigIntegeror(BigInteger y)Return the logical (bit-wise) "(inclusive) or" of two BigIntegers.BigIntegerpow(int exponent)Calculate the integral power of a BigInteger.static BigIntegerprobablePrime(int bitLength, Random rnd)Return a BigInteger that is bitLength bits long with a probability < 2^-100 of being composite.BigIntegerremainder(BigInteger val)BigIntegersetBit(int n)BigIntegershiftLeft(int n)BigIntegershiftRight(int n)intsignum()BigIntegersubtract(BigInteger val)booleantestBit(int n)byte[]toByteArray()java.lang.StringtoString()java.lang.StringtoString(int radix)voidtoStringBuffer(int radix, java.lang.StringBuffer sb)static BigIntegervalueOf(long val)Return a (possibly-shared) BigInteger with a given long value.BigIntegerxor(BigInteger y)Return the logical (bit-wise) "exclusive or" of two BigIntegers.
-
-
-
Field Detail
-
ZERO
public static final BigInteger ZERO
The constant zero as a BigInteger.
-
ONE
public static final BigInteger ONE
The constant one as a BigInteger.
-
TEN
public static final BigInteger TEN
The constant ten as a BigInteger.
-
-
Constructor Detail
-
BigInteger
public BigInteger(java.lang.String s, int radix) throws InvalidNumberException- Throws:
InvalidNumberException
-
BigInteger
public BigInteger(java.lang.String val) throws InvalidNumberException- Throws:
InvalidNumberException
-
BigInteger
public BigInteger(byte[] val) throws InvalidNumberException- Throws:
InvalidNumberException
-
BigInteger
public BigInteger(int signum, byte[] magnitude) throws InvalidNumberException- Throws:
InvalidNumberException
-
BigInteger
public BigInteger(int numBits, Random rnd)
-
BigInteger
public BigInteger(int bitLength, int certainty, Random rnd)
-
-
Method Detail
-
probablePrime
public static BigInteger probablePrime(int bitLength, Random rnd)
Return a BigInteger that is bitLength bits long with a probability < 2^-100 of being composite.- Parameters:
bitLength- length in bits of resulting numberrnd- random number generator to use- Throws:
java.lang.ArithmeticException- if bitLength < 2
-
valueOf
public static BigInteger valueOf(long val)
Return a (possibly-shared) BigInteger with a given long value.
-
signum
public int signum()
-
compareTo
public int compareTo(BigInteger val)
-
min
public BigInteger min(BigInteger val)
-
max
public BigInteger max(BigInteger val)
-
add
public BigInteger add(BigInteger val)
-
subtract
public BigInteger subtract(BigInteger val)
-
multiply
public BigInteger multiply(BigInteger y)
-
divide
public BigInteger divide(BigInteger val)
-
remainder
public BigInteger remainder(BigInteger val)
-
divideAndRemainder
public BigInteger[] divideAndRemainder(BigInteger val)
-
mod
public BigInteger mod(BigInteger m)
-
pow
public BigInteger pow(int exponent)
Calculate the integral power of a BigInteger.- Parameters:
exponent- the exponent (must be non-negative)
-
modInverse
public BigInteger modInverse(BigInteger y)
-
modPow
public BigInteger modPow(BigInteger exponent, BigInteger m)
-
gcd
public BigInteger gcd(BigInteger y)
-
isProbablePrime
public boolean isProbablePrime(int certainty)
Returns
trueif this BigInteger is probably prime,falseif it's definitely composite. Ifcertaintyis<= 0,trueis returned.- Parameters:
certainty- a measure of the uncertainty that the caller is willing to tolerate: if the call returnstruethe probability that this BigInteger is prime exceeds(1 - 1/2certainty). The execution time of this method is proportional to the value of this parameter.- Returns:
trueif this BigInteger is probably prime,falseif it's definitely composite.
-
shiftLeft
public BigInteger shiftLeft(int n)
-
shiftRight
public BigInteger shiftRight(int n)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(int radix)
-
toStringBuffer
public void toStringBuffer(int radix, java.lang.StringBuffer sb)
-
intValue
public int intValue()
-
longValue
public long longValue()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
doubleValue
public double doubleValue()
-
abs
public BigInteger abs()
-
negate
public BigInteger negate()
-
bitLength
public int bitLength()
Calculates ceiling(log2(this < 0 ? -this : this+1)) See Common Lisp: the Language, 2nd ed, p. 361.
-
toByteArray
public byte[] toByteArray()
-
and
public BigInteger and(BigInteger y)
Return the logical (bit-wise) "and" of two BigIntegers.
-
or
public BigInteger or(BigInteger y)
Return the logical (bit-wise) "(inclusive) or" of two BigIntegers.
-
xor
public BigInteger xor(BigInteger y)
Return the logical (bit-wise) "exclusive or" of two BigIntegers.
-
not
public BigInteger not()
Return the logical (bit-wise) negation of a BigInteger.
-
andNot
public BigInteger andNot(BigInteger val)
-
clearBit
public BigInteger clearBit(int n)
-
setBit
public BigInteger setBit(int n)
-
testBit
public boolean testBit(int n)
-
flipBit
public BigInteger flipBit(int n)
-
getLowestSetBit
public int getLowestSetBit()
-
bitCount
public int bitCount()
Count one bits in a BigInteger. If argument is negative, count zero bits instead.
-
compareTo
public int compareTo(java.lang.Object other) throws java.lang.ClassCastExceptionDescription copied from interface:ComparableMust return > 0 if this object is greater than the other one, < 0 if its smaller, and 0 if they are equal.- Specified by:
compareToin interfaceComparable- Throws:
java.lang.ClassCastException
-
-