cancel
Showing results for 
Search instead for 
Did you mean: 

Newcomers Start Here

spiridonoviouri
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

https://github.com/yur-spiridonov/Decimal-rounding-of-binary-numbers/commit/0e114f5c0a6a0bfc882e6f92...

 

0 Likes
1 Reply
spiridonoviouri
Journeyman III

Find the difference of the following numbers in Excel:
1.23456789012345E21-1.23456789012341E21
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 https://onlinegdb.com/UDRshDW3l.
Here is my code for adding/subtracting double numbers. You can enter any number in the input and get correct decimal answers.

0 Likes