Boost logo

Boost :

From: Matt Borland (matt_at_[hidden])
Date: 2025-01-20 14:41:36


> Its an interesting point, and I was interested to see if the authors will make some strong case
> that decimal floating-point is needed in finance. Obviously, as you mention, if financial calculations are supposed to be
> rounded to cents at every stage, one could write the entire software operating with integers (cents), and only converting to dollars and cents at
> the report printing stage.
>

> Similarly, in the bitcoin domain, AFAIK, transfers and accounting is supposed to be done not in floating point but in integer satoshi.
>

> But should it be done this way or in floating decimals? Is it possible to emulate decimal fixed-point using decimal floating-point?

In Reuben's MySQL case that was previously answered I don't see any reason we can't replicate fixed-point. The general case would obviously be different but restricted subsets it's fine. We also have the rescale function you brought up in your pre-review comments.

> The user guide is silent on any of these questions, so I have not been able to make up my mind if this library is needed or not in finance.
>

> For general mathematical use, and any sort of scientitic calculations, I am now 100% convinced decimals must not be used.
>

> The only other conceivable use, to write a spreadsheet and/or calculator software,
> but again there is nothing in the docs to inform us how is this supposed to be accomplished.
>

There are actually a few examples on financial calculations, since you asked for this in pre-reivew, that are discussed in the docs. This one even shows you how to parse and use CSV data since that's tied to calculations with your spreadsheets:

https://github.com/cppalliance/decimal/blob/develop/examples/moving_average.cpp

and this one shows you how to parse the CSV data and then leverage our designed integration with Boost.Math:

https://github.com/cppalliance/decimal/blob/develop/examples/statistics.cpp

Matt





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