Skip to content

Program seems to hang in frexp for decimal128_t having large exponent #1329

@ckormanyos

Description

@ckormanyos

I haven't quite figured out why, but the program below seems to hang indefinitely in the frexp function. I can't reach the debug line. It seems like there might be some wrong assumptions in the frexp function. I remember myself having quite a bit of trouble with the impl of frexp. I think this is a real issue, but I can't yet figure out what's going on.

Basically, the argument to frexp is

$$ \dfrac{104743{\times}10^{500}}{204745}{\approx}5.11577816308090551661823243546851{\times}10^{499} $$

which should be a valid decimal128_t for frexp, but maybe my assumptions in the test code are faulty?

#include <boost/decimal/decimal128_t.hpp>
#include <boost/decimal/cmath.hpp>
#include <boost/decimal/iostream.hpp>

volatile unsigned debug { };

auto main() -> int
{
  boost::decimal::decimal128_t arg_x { 104743, 500 };

  arg_x /= 204745;

  {
    std::stringstream strm { };

    strm << std::setprecision(std::numeric_limits<boost::decimal::decimal128_t>::digits10)
          << "arg_x: " << arg_x;

    std::cout << strm.str() << std::endl;
  }

  int exp2 { };

  // The program hangs here in frexp.
  const boost::decimal::decimal128_t frexp_result { frexp(arg_x, &exp2) };

  ++debug;
}

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions