Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#10924 closed Bugs (fixed)

conversion of float/double to cpp_dec_float_100 causes hang before main() on cygwin

Reported by: anonymous Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.57.0 Severity: Problem
Keywords: cygwin multiprecision Cc: e_float@…

Description

It looks like g++ generates bad code for:

cpp_dec_float_100 x = 1.0;

A program with this line hangs with full cpu usage, never entering main(). If 1.0 is replaced with an integer the problem disappears.

I'm using x86_64-pc-cygwin-g++ version 4.8.3, compiling with:

g++ -g -o gcc_bug_test1 gcc_bug_test1.cpp -I "$BOOST_PATH"

on a fresh install using setup-x86_64.exe with mirror cs.vt.edu.

gcc_bug_test1.cpp :

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

using namespace std;
namespace mp = boost::multiprecision;

int main(int argc, char *argv[])
{
	mp::cpp_dec_float_100 x = 1.0; // -3;
	return 0;
}

Change History (4)

comment:1 by John Maddock, 8 years ago

Cc: e_float@… added

Works for me with Mingw64 and msvc. Can you debug? What happens in GDB - does it get stuck in an infinite loop somewhere?

comment:2 by anonymous, 8 years ago

The most computationally intensive operation in cpp_dec_float before main() is the generation of a static constant table of p2 for -128 < p < +128.

It would help us if you could std::cout << "something clever" before and after the table is generated ?

If you look near line 2345 in boost/cpp_dec_float.hpp, you will find a potential location for this diagnostic.

Thank you for your report.

comment:3 by John Maddock, 8 years ago

Resolution: fixed
Status: newclosed

Turns out this is quite a pervasive issue - if there are no long double math functions (as on cygwin) then a call such as:

stdlibfunc(BIG_VALUE)

may simply return infinity as BIG_VALUE gets silently converted to double inside "stdlibfunc". In this particular case it's frexp/ldexp that are basically returning nonsense and breaking the program invariants.

Simplistic fix in https://github.com/boostorg/multiprecision/commit/4340817fd818b80df2295060eafdf79549d88683

comment:4 by John Maddock, 8 years ago

Also added some assertions for the preconditions which get broken on cygwin: https://github.com/boostorg/multiprecision/commit/ca1f4697724fbb3dc3afed465e2e027ef4d4522d

Note: See TracTickets for help on using tickets.