DFP
Decimal Floating Point
Java class library
|
Introduction
- What is dfp?
Dfp is a radix 10000 floating point math library. It features compile-time
defineable precision, usual arithmetic functions (add, subtract, multiply,
divide, etc.), and a set of mathematical functions including: natural
logarithm and exponential, trigonometic functions and their inverses.
Dfp also has IEEE-854 defined abilities such as user-specified rounding
modes, user-defineable trap handlers, and status flaqs.
- Design Goals
The following design goals were used to guide development of dfp.
- Accurate representation of decimal numbers.
- Accurate, well defined results
- Ability to work with high precision. Ability to set precision
at compile time.
- Portability.
- Ease of use
- Performance
- Major Design Decisions
- Radix of 10000 was chosen because it offer exact representation of
decimal numbers and better performance than a smaller radix would.
- Dfp is written in Java, this makes it somewhat portable to
start. To enhance portabilty more, it uses a minimal subset
of the language and core library APIs. This will ensure
portabity across Java implementations, and to other programming
languages.
- Dfp complies with IEEE-854 with a few minor
exceptions. If strict
compliance is desired, the subclass
rossi.dfp.dfpdec
fixes most of these these minor inconsitancies at the cost of
some performance.
- Comparison with double and Big Decimal
- Dfp mantains all the features of double along with other
IEEE specified features. Like BigDecimal, it can accurately
represent decimal numbers.
- Feature comparison:
| Feature | double | BigDecimal | dfp |
| Precision | Fixed | Variable | Compile time selectable |
| Floating/Fixed point | Floating | Fixed | Floating |
| Accurately represent decimal numberfs | no | yes | yes |
| IEEE Rounding modes | no | yes | yes |
| IEEE Flags | no | no | yes |
| IEEE Traps | no | no | yes |
| Square Root | yes | no | yes |
| Trig Functions | yes | no | yes |
| Exp and Log | yes | no | yes |
- Ease of use and performance
While it cannot compete with the ease of use and performance of
double, dfp beats BigDecimal
in both these areas.
It offers familiar methods such as add(), subtact(), multiply(),
and divide(). Each of these functions take only a single argument
which is the other dfp to be operated on. For example to divide
the dfp named dfpA by the dfp named dfpB ,
the following code snippet will do the job:
dfp result = dfpA.divide(dfpB);
There is no need to specify rounding modes or a scalar as with
BigDecimal. This simplifies usage considerably.
|