Decimal Floating Point
Java class library

SourceForge.net Logo


  1. 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.

  2. 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

  3. 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.

  4. 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:

      PrecisionFixedVariableCompile time selectable
      Floating/Fixed pointFloatingFixedFloating
      Accurately represent decimal numberfsnoyesyes
      IEEE Rounding modesnoyesyes
      IEEE Flagsnonoyes
      IEEE Trapsnonoyes
      Square Rootyesnoyes
      Trig Functionsyesnoyes
      Exp and Log yesnoyes

    • 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.