johnmcfarlane / cnl

A Compositional Numeric Library for C++
Boost Software License 1.0
641 stars 62 forks source link

Bug introduced by c1d418d6 #865

Closed hbe72 closed 3 years ago

hbe72 commented 3 years ago

Describe the bug: Testcase:

TEST(math, descale_change_introduced_problem)
{
    using T1 = cnl::static_number<39,-30,cnl::neg_inf_rounding_tag, cnl::saturated_overflow_tag, std::int16_t>;
    T1 a{12.4434319436550140};
    EXPECT_NEAR(12.4434319436550140, (double) a, 0.000001);
    std::ostringstream ss;
    std::ostringstream ref;
    ss << a;
    ref << 12.4434;
    EXPECT_EQ(ss.str(), ref.str());
}

Fails with:

Expected equality of these values:
  ss.str()
    Which is: "4.009767005498695985e-1292913986"
  ref.str()
    Which is: "12.4434"

To Reproduce:

This commit breaks the test case:

commit c1d418d6864ab7825c0a7b0419f33c643b3ee5c1
Author: John McFarlane <github@john.mcfarlane.name>
Date:   Sat Apr 10 21:58:15 2021 +0100

    Reduce trailing zeros in _impl::descale

This works for earlier versions of CNL.

This was detected by random std::cout printing. Reproduction requires quite specific numbers.

hbe72 commented 3 years ago

That test btw. runs for 30 seconds. Quite a long loop CNL has created...

johnmcfarlane commented 3 years ago

Here's a reduced repro. It's likely stuck in the loop in descale. With some work, I'm confident I can make it take longer then a minute...

johnmcfarlane commented 3 years ago

How's it looking now?

hbe72 commented 3 years ago

Works. Thanks!!!

johnmcfarlane commented 3 years ago

https://godbolt.org/z/YrGznjd69