Boost logo

Boost :

From: Rainer Deyke (rdeyke_at_[hidden])
Date: 2024-05-14 12:51:43


On 13.05.24 15:44, Matt Borland via Boost wrote:
> Hello,
>
> For the past year Chris Kormanyos and I have been working on a new library to implement IEEE 754 decimal floating point types. We are pleased to announce the library is now in beta, and can be found at: https://github.com/cppalliance/decimal, and the documentation is at: https://cppalliance.org/decimal/decimal.html
>
> First, what are Decimal Floating Point Numbers? They are floating point numbers where the significand is stored in base-10 (decimal) instead of base-2 (binary). This means that numbers can be represented exactly avoiding cases such as the famous 0.1 + 0.2 != 0.3: https://0.30000000000000004.com.
>
>
> The library provides types decimal32, decimal64, and decimal128 as specified in IEEE 754 and STL-like functionality. The library is header-only, has no dependencies, and only requires C++14. It provides most of the STL functionality that you are familiar with such as <cmath>, <cstdlib>, <charconv>, etc. We are proceeding as a beta right now rather than pursuing complete boost review as we are missing STL features such as C++17 special math, and believe we can continue to increase performance. We do intend to go through the review process at a later time.
>
> Please give the library a go, and let us know how we can make it better. We look forward to any and all feedback. If you use the Cpplang slack channel I am active (from the Central European Time zone) on both #boost and #boost-decimal.
>
> On a personal note as of today I have also moved from being employed half-time to full-time with the C++ Alliance. This affords me a greater opportunity to develop and maintain new and existing Boost libraries.

I don't really see the use for this.

For actual physical measurements (which are inexact by nature), binary
floating point is more efficient and more accurate.

For money values (which are exact by nature), I would stick to integer
or fixed point types. Floating point types, binary or decimal, are
inherently inexact: the number of (binary) digits is fixed, so as more
digits are added to the left, digits start getting dropped to right.
Worse, adding extra digits to the decimal point is just plain wrong. If
I have to pay 25% of an amount rounded to cents, then correctly rounding
to cents is as important as calculating the 25% correctly.

If I wanted actually exact fractions, without any rounding, I would use
boost::rational. Fixed point and floating point are both equally
incorrect, and using decimal instead of binary does nothing to make
things more accurate. What's the point of 0.2+0.3=0.5 if 3*(1/3)!=1?

The only real advantage of decimal floating point is lossless conversion
to and from decimal text representations. I guess decimal floating
point could be useful for a calculator app or a spreadsheet, where the
text representation of a number is paramount, but not much else.

-- 
Rainer Deyke (rainerd_at_[hidden])

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk