Skip to content

cpp_dec_float incorrect constructing from string #499

Closed
@yaroslavchahovets

Description

@yaroslavchahovets

When constructing cpp_dec_float from certain string values which don't represent correct numbers, we expect that the exception is thrown, but the object is successfully constructed:

#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>

using boost::multiprecision::cpp_dec_float_50;

int main()
{
    std::cout.precision(10);

    cpp_dec_float_50 val1{"12a3.4"};
    std::cout << "no exception. val1=" << val1 << "\n";

    cpp_dec_float_50 val2{"1.2a34"};
    std::cout << "no exception. val2=" << val2 << "\n";

    return 0;
}

Output:
no exception. val1=12.4
no exception. val2=1.00000002

This bug is reproduced on Boost 1.79.0 and 1.80.0. Also it is reproduced on current repository https://github.com/boostorg/boost.git (as of 2022-10-05). The behaviour is correct on Boost 1.78.0. Compilers: gcc 9.4.0 and gcc 10.3.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions