Showing results for 
Search instead for 
Did you mean: 

Newcomers Start Here

Journeyman III

Binary arithmetic for decimal numbers

I propose a new approach to the implementation of binary arithmetic on decimal numbers, which gives the decimal precision of binary calculations. This allows you to implement a bitwise comparison of binary numbers in float, double and other formats. The new approach makes it possible to calculate exact decimal values, including when subtracting close and equal binary equivalents of decimal numbers, which makes the process of comparing binary numbers trivial.
All this is achieved using the algorithm for the correct rounding of binary floating point numbers, presented at


1 Reply
Journeyman III

Find the difference of the following numbers in Excel:
You will get the result 39845888. Calculate this difference using any programming language that supports the IEEE754 standard and you will get the same answer. Although in decimal arithmetic you will get the exact answer - 4.0E7.
In the arithmetic of binary equivalents of decimal numbers, which I propose, the result will be exactly the same as in decimal arithmetic. You can check it in the online compiler and debugger for c/c++ at
Here is my code for adding/subtracting double numbers. You can enter any number in the input and get correct decimal answers.