Opened 6 years ago
Closed 5 years ago
#12908 closed Bugs (fixed)
Assert in next.hpp function float_distance with boost::multiprecision::cpp_dec_float_50
Reported by: | Paul A. Bristow | Owned by: | John Maddock |
---|---|---|---|
Milestone: | Boost 1.65.0 | Component: | multiprecision |
Version: | Boost 1.63.0 | Severity: | Problem |
Keywords: | multiprecision math float_distance cpp_dec_float_50 decimal | Cc: |
Description
A very few inputs to float_distance cause a BOOST_ASSERT to fire at line 380 BOOST_ASSERT(result == floor(result));
A single example found is:
result 7.5104779560206957400348257098619840395218651150916, floor(result) = 7.0000000000000000000000000000000000000000000000000 Float_distance parameter a = 1.3267246652422002236350992977580796601287935546380, b = 1.3267246652422002236350992977580796601287935546381 1> Assertion failed: result == floor(result), file i:\modular-boost\boost\math\special_functions\next.hpp, line 387
The result to return from float_distance is expected to be an integral value, but for this example is not.
This example was found using Boost.Test testing all floating-point types, including built-in and Boost.Multiprecision types. Only the decimal type failed, with the binary Boost.Multiprecision type working as expected.
(The objective of using float_distance was to find the number of bits 'wrong' in estimation of the Lambert_w function. The float_distance function may be less informative with decimal types? After commenting out the assert or building release version works as expected passing the Boost.Test BOOST_CHECK_CLOSE_FRACTION. The complete diagnostic information is below).
x = 5.0000000000000000000000000000000000000000000000000, 1st approximation = 1.3580516899453466985241032060217449722205837894767 Iteration #0, w0 1.3580516899453466985241032060217449722205837894767, w1 = 1.3267307975239098478154332577910055570547859817317, difference = 0.023607571694190959083521171155401856568500751382772, relative 0.023607571694190959083521171155401856568500751382772 f'(x) = 0.030637621044026712522396263905986832827907006395521, f(x) = -0.031320892421436850708669948230739415165797807744979 Iteration #1, w0 1.3267307975239098478154332577910055570547859817317, w1 = 1.3267246652422002700196628232995006483530574240972, difference = 4.6221208290103786210868929801267062674723441825020e-06, relative 4.6221208290103786210868929801267062674723441825020e-06 f'(x) = 6.1322548262011945248563701546564283036693266139626e-06, f(x) = -6.1322817095777957704344915049087017285576344382728e-06 1> Iteration #2, w0 1.3267246652422002700196628232995006483530574240972, w1 = 1.3267246652422002236350992977580796601287935546381, difference = 3.4961710399100545033506658399263431373381321572551e-17, relative 3.4961710399100545033506658399263431373381321572551e-17 f'(x) = 4.6384563525541419450109229082502667458865618273589e-17, f(x) = -4.6384563525541420988224263869459174491854618532511e-17 Refined 1.3267246652422002236350992977580796601287935546380 after 2 iterations, difference = 1.5130298669100961690698000000000000000000000000000e-50 result 7.5104779560206957400348257098619840395218651150916, floor(result) = 7.0000000000000000000000000000000000000000000000000 Float_distance parameter a 1.3267246652422002236350992977580796601287935546380, b = 1.3267246652422002236350992977580796601287935546381 Assertion failed: result == floor(result), file i:\modular-boost\boost\math\special_functions\next.hpp, line 387 unknown location : fatal error : in "test_main": abort() has been called i:\modular-boost\libs\math\test\test_lambert_w.cpp(183): last checkpoint
* 1 failure is detected in the test module "Master Test Suite"
This was fixed in https://github.com/boostorg/math/commit/9b2f8781034702a650ed375e4ba05588339fedd7#diff-6b50972ab602a4e7e699c7c18660d431