Chapter 12. Big Numbers

   

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

Table of Contents
Part  IV.   The Joys of Computation


Chapter 12. Big Numbers

In the first three chapters of this book, we looked at the limitations of both integers and floating-point numbers. Of course, one major limitation is their precision?athe long integer type has 19 digits, and the double floating-point type has about 17 significant digits. We also saw how the Java floating-point types only implement the default round to nearest rounding mode of the IEEE 754 floating-point standard.

Besides the primitive numeric types, Java implements big number, or arbitrary-precision , data types?athe BigInteger and BigDecimal classes in the java.math package. These classes represent numbers that have arbitrary numbers of digits of precision, and they have methods to perform the common arithmetic operations on these values. The operations are implemented in software, and so there will be significant performance penalties.

A BigInteger object represents an integer value. A BigDecimal object represents a decimal value?aa value that has a whole part to the left of the decimal point and a fractional part to the right of the point. BigDecimal values also allow you to specify how they are rounded during arithmetic operations.

BigInteger and BigDecimal values are immutable. Once you've created such an object and initialized its value, you cannot change the value. Most of the methods that operate on these values create new objects to hold the result values.

This chapter takes a brief look at these two classes. We'll look at BigInteger values and prime numbers. (Chapter 15 will have a lot more to say about prime numbers.) We'll also write some BigDecimal functions that will enable some interesting computations in the next chapter.


   
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