Giter VIP home page Giter VIP logo

decimalfloatingpointexample's Introduction

Example of Decimal Floating Point usage

Overview

In the context of standardization of CEN TC 434 WG1 (European e-invoicing) a problem occurred that invoices differ in some values significantly although provided by the same data input. The suggested solution was threefold:

  1. Define the way of rounding to be used. For instance, German law requires to use HALF-UP rounding for VAT calculation.

  2. Define only ways to calculate an invoice value, which lead to the same results. The gross total can be calculated by:

    1. Adding all net values of each invoice line and multiply the sum with the VAT tax.
    2. Multiply the VAT tax to each invoice line net value and add the gross line amounts. The latter way includes rounding of intermediate results, which leads further away from the arithmetic truth and should be avoided.
  3. Define a way to do accurate arithmetic calculation by expressing that the implementation have to be as accurate as if been using decimal-based floating-point arithmetic. First standardized in 1987 by IEEE 854, integrated with IEEE 754 in 2008, latest IEEE 754:2019 and also available as ISO standard.

My kind regards to the former IEEE 754 chair, David Hough, and editor, Mike Cowlishaw, who took the time to answer to my questions and provide guidance. Mike is maintaining a very good FAQ on Decimal based floating point.

Show & Tell

The example is based on work from the Princeton University.

Example output from command line

The green boxes are using decimal based floating point and the red boxes binary based floating point.

NOTE: Most evident the last box, where adding three times 0,1 is not exactly 0,3.

Run the example

Call from a command-line in the root directory of the repository: "gradlew clean build"

Precision vs. accuracy

  • Precision = tightness of specification
  • Accuracy = correctness

As explained in https://introcs.cs.princeton.edu/java/91float/.

decimalfloatingpointexample's People

Contributors

svanteschubert avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.