|
Boost : |
From: Kostas Savvidis (kotika98_at_[hidden])
Date: 2025-01-31 13:59:45
> On 20 Jan 2025, at 16:41, Matt Borland <matt_at_[hidden]> wrote:
>
> 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
Thanks, the examples indeed show how to do it.
Is it a good thing or a bad thing that the result of those calculations is expected to be exactly the same as with doubles? (within machine epsilon)
Its a good thing, but leaves the question "when should we use decimal?" unanswered.
I became interested in this subject when I was working with some stock exchange data and saw numbers like 32.1100006103
in the CSV. Obviously the price of the stock was 32.11. How is that even possible? Doubles and floats do not represent this number exactly,
but if you do
double s=32.11;
std::cout << s ;
you will get 32.11 back. To get back e.g. 32.11000061 you have to do
float s=32.11;
std::cout << std::setprecision(8) << std::fixed << s << "\n";
The fact that the exchange and/or data provider somehow did muck this up, may or may not mean this could have been avoided
by using decimal. The mistake is: printing with more digits than machine epsilon.
I am more puzzled than ever about what this library is for.
Cheers,
Kostas
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk