Decimal Floating Point
Java class library
- 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.
- Ease of use
- 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
- Dfp complies with IEEE-854 with a few minor
exceptions. If strict
compliance is desired, the subclass
fixes most of these these minor inconsitancies at the cost of
- 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:
|Precision||Fixed||Variable||Compile time selectable|
|Accurately represent decimal numberfs||no||yes||yes|
|IEEE Rounding modes||no||yes||yes|
|Exp and Log ||yes||no||yes|
- Ease of use and performance
While it cannot compete with the ease of use and performance of
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
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.