@@ -56,17 +56,31 @@ namespace local
5656
5757 auto result_is_ok = bool { };
5858
59+ NumericType delta { };
60+
5961 if (b == static_cast <NumericType>(0 ))
6062 {
61- result_is_ok = (fabs (a - b) < tol);
63+ delta = fabs (a - b); // LCOV_EXCL_LINE
64+
65+ result_is_ok = (delta < tol); // LCOV_EXCL_LINE
6266 }
6367 else
6468 {
65- const auto delta = fabs (1 - (a / b));
69+ delta = fabs (1 - (a / b));
6670
6771 result_is_ok = (delta < tol);
6872 }
6973
74+ // LCOV_EXCL_START
75+ if (!result_is_ok)
76+ {
77+ std::cerr << std::setprecision (std::numeric_limits<NumericType>::digits10) << " a: " << a
78+ << " \n b: " << b
79+ << " \n delta: " << delta
80+ << " \n tol: " << tol << std::endl;
81+ }
82+ // LCOV_EXCL_STOP
83+
7084 return result_is_ok;
7185 }
7286
@@ -93,7 +107,7 @@ namespace local
93107 auto trials = static_cast <std::uint32_t >(UINT8_C (0 ));
94108
95109 #if !defined(BOOST_DECIMAL_REDUCE_TEST_DEPTH)
96- constexpr auto count = (sizeof (decimal_type) == static_cast <std::size_t >(UINT8_C (4 ))) ? static_cast <std::uint32_t >(UINT32_C (0x400 )) : static_cast <std::uint32_t >(UINT32_C (0x40 ));
110+ constexpr auto count = (sizeof (decimal_type) == static_cast <std::size_t >(UINT8_C (4 ))) ? static_cast <std::uint32_t >(UINT32_C (0x200 )) : static_cast <std::uint32_t >(UINT32_C (0x40 ));
97111 #else
98112 constexpr auto count = (sizeof (decimal_type) == static_cast <std::size_t >(UINT8_C (4 ))) ? static_cast <std::uint32_t >(UINT32_C (0x40 )) : static_cast <std::uint32_t >(UINT32_C (0x4 ));
99113 #endif
@@ -114,13 +128,13 @@ namespace local
114128
115129 if (!result_log_is_ok)
116130 {
117- // LCOV_EXCL_START
118- std::cout << " x_flt : " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << x_flt << std::endl;
119- std::cout << " val_flt: " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << val_flt << std::endl;
120- std::cout << " val_dec: " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << val_dec << std::endl;
131+ // LCOV_EXCL_START
132+ std::cerr << " x_flt : " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << x_flt << std::endl;
133+ std::cerr << " val_flt: " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << val_flt << std::endl;
134+ std::cerr << " val_dec: " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << val_dec << std::endl;
121135
122136 break ;
123- // LCOV_EXCL_STOP
137+ // LCOV_EXCL_STOP
124138 }
125139 }
126140
@@ -155,13 +169,13 @@ namespace local
155169
156170 if (!result_log_is_ok)
157171 {
158- // LCOV_EXCL_START
159- std::cout << " x_flt : " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << x_flt << std::endl;
160- std::cout << " val_flt: " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << val_flt << std::endl;
161- std::cout << " val_dec: " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << val_dec << std::endl;
172+ // LCOV_EXCL_START
173+ std::cerr << " x_flt : " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << x_flt << std::endl;
174+ std::cerr << " val_flt: " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << val_flt << std::endl;
175+ std::cerr << " val_dec: " << std::scientific << std::setprecision (std::numeric_limits<float_type>::digits10) << val_dec << std::endl;
162176
163177 break ;
164- // LCOV_EXCL_START
178+ // LCOV_EXCL_START
165179 }
166180 }
167181
@@ -312,7 +326,123 @@ namespace local
312326
313327 return result_is_ok;
314328 }
315- }
329+
330+ auto test_log_64 (const int tol_factor) -> bool
331+ {
332+ using decimal_type = boost::decimal::decimal64;
333+
334+ using val_ctrl_array_type = std::array<double , 28U >;
335+
336+ const val_ctrl_array_type ctrl_values =
337+ {{
338+ // Table[N[Log[111 10^n], 17], {n, -3, 24, 1}]
339+ -2.1982250776698029 , 0.10436001532424277 , 2.4069451083182885 ,
340+ 4.7095302013123341 , 7.0121152943063798 , 9.3147003873004255 ,
341+ 11.617285480294471 , 13.919870573288517 , 16.222455666282563 ,
342+ 18.525040759276608 , 20.827625852270654 , 23.130210945264700 ,
343+ 25.432796038258745 , 27.735381131252791 , 30.037966224246837 ,
344+ 32.340551317240882 , 34.643136410234928 , 36.945721503228974 ,
345+ 39.248306596223019 , 41.550891689217065 , 43.853476782211111 ,
346+ 46.156061875205156 , 48.458646968199202 , 50.761232061193248 ,
347+ 53.063817154187294 , 55.366402247181339 , 57.668987340175385 ,
348+ 59.971572433169431
349+ }};
350+
351+ std::array<decimal_type, std::tuple_size<val_ctrl_array_type>::value> log_values { };
352+
353+ int nx { -3 };
354+
355+ bool result_is_ok { true };
356+
357+ const decimal_type my_tol { std::numeric_limits<decimal_type>::epsilon () * static_cast <decimal_type>(tol_factor) };
358+
359+ for (auto i = static_cast <std::size_t >(UINT8_C (0 )); i < std::tuple_size<val_ctrl_array_type>::value; ++i)
360+ {
361+ // Table[N[Log[111 10^n], 17], {n, -3, 24, 1}]
362+
363+ const decimal_type x_arg { 111 , nx };
364+
365+ log_values[i] = log (x_arg);
366+
367+ ++nx;
368+
369+ const auto result_log_is_ok = is_close_fraction (log_values[i], decimal_type (ctrl_values[i]), my_tol);
370+
371+ result_is_ok = (result_log_is_ok && result_is_ok);
372+ }
373+
374+ return result_is_ok;
375+ }
376+
377+ auto test_log_128 (const int tol_factor) -> bool
378+ {
379+ using decimal_type = boost::decimal::decimal128;
380+
381+ using str_ctrl_array_type = std::array<const char *, 28U >;
382+
383+ const str_ctrl_array_type ctrl_strings =
384+ {{
385+ // Table[N[Log[111 10^n], 36], {n, -3, 24, 1}]
386+ " -2.19822507766980291629063345609911975" ,
387+ " 0.104360015324242767727357998585244453" ,
388+ " 2.40694510831828845174534945326960866" ,
389+ " 4.70953020131233413576334090795397287" ,
390+ " 7.01211529430637981978133236263833708" ,
391+ " 9.31470038730042550379932381732270128" ,
392+ " 11.6172854802944711878173152720070655" ,
393+ " 13.9198705732885168718353067266914297" ,
394+ " 16.2224556662825625558532981813757939" ,
395+ " 18.5250407592766082398712896360601581" ,
396+ " 20.8276258522706539238892810907445223" ,
397+ " 23.1302109452646996079072725454288865" ,
398+ " 25.4327960382587452919252640001132507" ,
399+ " 27.7353811312527909759432554547976149" ,
400+ " 30.0379662242468366599612469094819792" ,
401+ " 32.3405513172408823439792383641663434" ,
402+ " 34.6431364102349280279972298188507076" ,
403+ " 36.9457215032289737120152212735350718" ,
404+ " 39.2483065962230193960332127282194360" ,
405+ " 41.5508916892170650800512041829038002" ,
406+ " 43.8534767822111107640691956375881644" ,
407+ " 46.1560618752051564480871870922725286" ,
408+ " 48.4586469681992021321051785469568928" ,
409+ " 50.7612320611932478161231700016412570" ,
410+ " 53.0638171541872935001411614563256212" ,
411+ " 55.3664022471813391841591529110099854" ,
412+ " 57.6689873401753848681771443656943496" ,
413+ " 59.9715724331694305521951358203787139" ,
414+ }};
415+
416+ std::array<decimal_type, std::tuple_size<str_ctrl_array_type>::value> log_values { };
417+ std::array<decimal_type, std::tuple_size<str_ctrl_array_type>::value> ctrl_values { };
418+
419+ int nx { -3 };
420+
421+ bool result_is_ok { true };
422+
423+ const decimal_type my_tol { std::numeric_limits<decimal_type>::epsilon () * static_cast <decimal_type>(tol_factor) };
424+
425+ for (auto i = static_cast <std::size_t >(UINT8_C (0 )); i < std::tuple_size<str_ctrl_array_type>::value; ++i)
426+ {
427+ const decimal_type x_arg { 111 , nx };
428+
429+ ++nx;
430+
431+ log_values[i] = log (x_arg);
432+
433+ static_cast <void >
434+ (
435+ from_chars (ctrl_strings[i], ctrl_strings[i] + std::strlen (ctrl_strings[i]), ctrl_values[i])
436+ );
437+
438+ const auto result_log_is_ok = is_close_fraction (log_values[i], ctrl_values[i], my_tol);
439+
440+ result_is_ok = (result_log_is_ok && result_is_ok);
441+ }
442+
443+ return result_is_ok;
444+ }
445+ } // namespace local
316446
317447auto main () -> int
318448{
@@ -340,6 +470,22 @@ auto main() -> int
340470 result_is_ok = (test_log_is_ok && test_log_between_1_and_2_is_ok && test_log_edge_is_ok && result_is_ok);
341471 }
342472
473+ {
474+ const auto result_pos64_is_ok = local::test_log_64 (512 );
475+
476+ BOOST_TEST (result_pos64_is_ok);
477+
478+ result_is_ok = (result_pos64_is_ok && result_is_ok);
479+ }
480+
481+ {
482+ const auto result_pos128_is_ok = local::test_log_128 (1'400'000 );
483+
484+ BOOST_TEST (result_pos128_is_ok);
485+
486+ result_is_ok = (result_pos128_is_ok && result_is_ok);
487+ }
488+
343489 result_is_ok = ((boost::report_errors () == 0 ) && result_is_ok);
344490
345491 return (result_is_ok ? 0 : -1 );
0 commit comments