
The short demonstration program linked from this page shows the results
achieved using decimal arithmetic as compared to binary floating point
arithmetic.
The program simply starts with the number nine (9), and repeatedly
divides it by ten (10), and should display the following result:
0.9 0.9
0.09 0.089999996
0.009 0.0090
0.0009 9.0E-4
0.00009 9.0E-5
0.000009 9.0E-6
9E-7 9.0000003E-7
9E-8 9.0E-8
9E-9 9.0E-9
9E-10 8.9999996E-10
where the left-hand column is the results given using the new BigDecimal
class, and the right-hand column is the results obtained using the
binary float datatype.
You can use the program for testing your installation of the decimal
package; the program is available in both
Java and
NetRexx:
Java
- Here's the source for the program.
View it, and save it as decdemo.java in a convenient
directory.
- If you haven't already done so, download
and install the decimal.jar file.
- Compile the program using the command
javac decdemo.java
- Run the program using the command
java decdemo
This should display the results shown above.
|
NetRexx
- Here's the source for the program.
View it, and save it as decdemo.nrx in a convenient
directory.
- If you haven't already done so, download
and install the decimal.jar file.
- Compile the program using the command
nrc decdemo
- Run the program using the command
java decdemo
This should display the results shown above.
|
Copyright © IBM Corporation, 1998. All rights reserved.
[
IBM home page |
Search |
Contact IBM |
Help |
Legal |
Privacy
]