Skip to content

Incorrect == for decimal64 #800

@libbooze

Description

@libbooze

Following code:

void compare_dec64()
{
    using namespace boost::decimal;
    using Dec= decimal64;
    std::print("{}\n", boost::typeindex::type_id<Dec>().pretty_name());
    const Dec a{1452241920, 1};
    const Dec b{ 9223372037, 11};
    std::print("max:{:.40e}\n", std::numeric_limits<Dec>::max());
    std::print("a  : {:.40e}\n", a);
    std::print("b  : {:.40e}\n", b);
    std::print("same {} \n\n", a  == b );
}

prints(on branch limits since master does not print max correctly):

boost::decimal::decimal64
max:9.9999999999999990000000000000000000000000e+384
a  : 1.4522419200000000000000000000000000000000e+10
b  : 9.2233720370000000000000000000000000000000e+20
same true 

I am pretty sure issue is uint64 overflow in

    delta_exp >= 0 ? lhs_sig *= detail::pow10(static_cast<comp_type>(delta_exp)) :
                     rhs_sig *= detail::pow10(static_cast<comp_type>(-delta_exp));

While I believe first intuition for fix will bet to just widen the operands I am actually not sure if that is best fix.

Not sure if this is limited to decimal64, took me a while to get correct values to trigger a bug, did not have time to check for other types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Boost ReviewCollected Comments from Boost Review PeriodBugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions