vpiotr / decimal_for_cpp

Decimal data type for C++
273 stars 68 forks source link

Edge case bug or feature? #67

Closed alex-hrb-0 closed 2 months ago

alex-hrb-0 commented 2 months ago

Hi there,

I'm using bankers rounding and I'm getting 0.64535 perfectly rounded to 0.6454 in the following example:

dec::decimal<1, dec::half_even_round_policy> s1(550), s2(550);
dec::decimal<4, dec::half_even_round_policy> p1(350.68), p2(359.2050);
std::cout << (p1 + p2) / (s1 + s2); 

But I probably don't need precision for s1 and s2 so I changed the precision from 1 to 0 for them:

dec::decimal<0, dec::half_even_round_policy> s1(550), s2(550);
dec::decimal<4, dec::half_even_round_policy> p1(350.68), p2(359.2050);
std::cout << (p1 + p2) / (s1 + s1); 

And I started getting 0.6453 instead of 0.6454 which seems wrong for the selected rounding method.

vpiotr commented 2 months ago

It's an edge case, corrected, thanks for reporting.