12.1 Big Integers

   

 
Java Number Cruncher: The Java Programmer's Guide to Numerical Computing
By Ronald  Mak

Table of Contents
Chapter  12.   Big Numbers

12.1 Big Integers

BigInteger objects are useful when we have values that are larger than what type long can handle. Like the values of the primitive integer types, a BigInteger value is encoded in the two's-complement format (see Chapter 2).

The class includes methods to perform the basic arithmetic operations on BigInteger objects. The result of such an operation is always a new BigInteger object, since the objects are immutable. The arithmetic methods include abs() , add() , divide() , divide AndRemainder() , max() , min() , mod() , multiply() , negate() , pow() , remainder() , and subtract() . Method signum () returns -1, 0, or +1, depending on whether the value is negative, zero, or positive, respectively.

There are also methods that perform some bitwise operations, such as and() , andNot() , bitLength() , clearBit() , flipBit() , not() , or() , setBit() , shiftLeft() , shiftRight() , testBit() , and xor() .

Method valueOf() is a "factory method"?ait creates a new BigInteger object from a long value. Method compareTo() compares a BigInteger value to another and returns -1, 0, or +1, depending on whether the value is less than, equal to, or greater than the other, respectively.


   
Top
 


Java Number Cruncher. The Java Programmer's Guide to Numerical Computing
Java Number Cruncher: The Java Programmers Guide to Numerical Computing
ISBN: 0130460419
EAN: 2147483647
Year: 2001
Pages: 141
Authors: Ronald Mak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net