#13148 closed Bugs (fixed)
Zero value cannot be converted from cpp_dec_float_50 to cpp_rational
| Reported by: | Owned by: | John Maddock | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | multiprecision |
| Version: | Boost 1.64.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
String "boost::multiprecision::cpp_rational result(d1);" eats CPU forever.
It is reproduced on boost_1_65_0_beta1 and boost_1_64_0.
boost::multiprecision::cpp_rational rationalfromStr(const char* str)
{
boost::multiprecision::cpp_dec_float_50 d1(str);
boost::multiprecision::cpp_rational result(d1); // <--- eats CPU forever
return result;
}
void test()
{
// this example is OK
{
boost::multiprecision::cpp_rational expected=1;
assert(expected == rationalfromStr("1"));
}
// this example is OK
{
boost::multiprecision::cpp_rational expected=boost::multiprecision::cpp_rational(25)/boost::multiprecision::cpp_rational(10);
assert(expected == rationalfromStr("2.5"));
}
// this example is OK
{
boost::multiprecision::cpp_rational expected=boost::multiprecision::cpp_rational(5)/boost::multiprecision::cpp_rational(1000);
assert(expected == rationalfromStr("0.005"));
}
// this example is OK
{
boost::multiprecision::cpp_rational expected=0;
assert(expected == boost::multiprecision::cpp_rational("0")); // direct cpp_rational from str is ok
}
// this example fails
{
boost::multiprecision::cpp_rational expected=0;
// reacheble code
assert(expected == rationalfromStr("0")); // cpp_rational from cpp_dec_float_50 is not ok
// unreacheble code
}
}
Change History (5)
comment:1 by , 5 years ago
comment:2 by , 5 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Fixed in https://github.com/boostorg/multiprecision/commit/37c813f764eec8ca7cd9beba3a9ba785503c6d21
Thanks for the report!
follow-up: 5 comment:4 by , 5 years ago
I've just this second merged to master, so it should be in 1.67.
Note:
See TracTickets
for help on using tickets.

Compiling with
-fsanitize=undefinedreveals an integer overflow:I can't reproduce with 1.63. It looks like this was introduced in the fix for #12625.