diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index d082c7602..551376209 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -72,6 +72,10 @@ test-suite examples : [ run legendre_stieltjes_example.cpp : : : [ requires cxx11_auto_declarations cxx11_defaulted_functions cxx11_lambdas ] ] #[ # run inverse_chi_squared_find_df_example.cpp ] [ run lambert_w_basic_example.cpp ] + #[ run lambert_w_basic_example.cpp : : : [ requires cxx11_numeric_limits ] ] + [ run lambert_w_simple_examples.cpp : : : [ requires cxx11_numeric_limits ] ] + [ run lambert_w_precision_example.cpp : : : [ requires cxx11_numeric_limits ] ] + [ run inverse_gamma_example.cpp ] [ run inverse_gamma_distribution_example.cpp : : : off:no ] diff --git a/example/lambert_w_basic_example.cpp b/example/lambert_w_basic_example.cpp index a8daed727..869416194 100644 --- a/example/lambert_w_basic_example.cpp +++ b/example/lambert_w_basic_example.cpp @@ -4,6 +4,10 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) +// Example of most basic call of both lambert W functions. +// Only requires C++03 +// (and optionally a call of max_digits10 to show precision). + #include // For lambert_w0 and wm1 functions. #include @@ -14,8 +18,10 @@ int main() double z = 2.0; double w0 = boost::math::lambert_w0(z); std::cout.setf(std::ios_base::showpoint); // Include any trailing zeros. - // std::cout.precision(std::numeric_limits::max_digits10); // Show all possibly significant digits. - // Avoid using max_digfigs10 so as many old compilers can run the most basic lambert_w0 test. + std::cout.precision(std::numeric_limits::max_digits10); // Show all possibly significant digits. + // Avoid using max_digfigs10 so as many old compilers can run the most basic lambert_w0 test? + // Require to get max_digits10 + // [ run lambert_w_basic_example.cpp : : : [ requires cxx11_numeric_limits ] ] std::cout << " lambert_w0(" << z << ") = " << w0 << std::endl; // lambert_w0(2.00000) = 0.852606 z = -0.2; double wm1 = boost::math::lambert_wm1(z); diff --git a/example/lambert_w_precision_example.cpp b/example/lambert_w_precision_example.cpp index 3d81c934d..6d963a17d 100644 --- a/example/lambert_w_precision_example.cpp +++ b/example/lambert_w_precision_example.cpp @@ -4,7 +4,7 @@ // (See accompanying file LICENSE_1_0.txt or // copy at http ://www.boost.org/LICENSE_1_0.txt). -//! Lambert W examples of controlling precision +//! Lambert W examples of controlling precision // #define BOOST_MATH_INSTRUMENT_LAMBERT_W // #define only for (much) diagnostic output. @@ -76,16 +76,16 @@ int main() std::cout.precision(std::numeric_limits::digits10); r = lambert_w0(z); // Default policy. - std::cout << "lambert_w0(z) cpp_bin_float_50 = " << r << std::endl; + std::cout << "lambert_w0(z) cpp_bin_float_50 = " << r << std::endl; //lambert_w0(z) cpp_bin_float_50 = 1.7455280027406993830743012648753899115352881290809 // [N[productlog[10], 50]] == 1.7455280027406993830743012648753899115352881290809 std::cout.precision(std::numeric_limits::max_digits10); std::cout << "lambert_w0(z) static_cast from cpp_bin_float_50 = " - << static_cast(r) << std::endl; + << static_cast(r) << std::endl; // double lambert_w0(z) static_cast from cpp_bin_float_50 = 1.7455280027406994 // [N[productlog[10], 17]] == 1.7455280027406994 - std::cout << "bits different from Wolfram = " - << static_cast(float_distance(static_cast(r), 1.7455280027406994)) + std::cout << "bits different from Wolfram = " + << static_cast(float_distance(static_cast(r), 1.7455280027406994)) << std::endl; // 0 @@ -96,7 +96,7 @@ int main() std::cout << std::showpoint << std::endl; // and show any significant trailing zeros too. float x = 10.; - std::cout << "Lambert W (" << x << ") = " << lambert_w0(x) << std::endl; + std::cout << "Lambert W (" << x << ") = " << lambert_w0(x) << std::endl; //] [/lambert_w_precision_0] /* @@ -118,7 +118,7 @@ Lambert W (10.0000000) = 1.74552800 cpp_bin_float_50 w50; w50 = lambert_w0(z50); std::cout.precision(std::numeric_limits::max_digits10); // 50 decimal digits. - std::cout << "Reference Lambert W (" << z << ") =\n " + std::cout << "Reference Lambert W (" << z << ") =\n " << w50 << std::endl; std::cout.precision(std::numeric_limits::max_digits10); // 17 decimal digits for double. double wr = static_cast(w50); @@ -136,7 +136,7 @@ Lambert W (10.0000000) = 1.74552800 std::cout << "epsilon for float = " << std::numeric_limits::epsilon() << std::endl; std::cout << "bits different from Halley step = " << static_cast(float_distance(w, ww)) << std::endl; //] [/lambert_w_precision_1] - + /* //[lambert_w_precision_output_1 @@ -169,7 +169,7 @@ Lambert W (10.0000000) = 1.74552800 cpp_bin_float_50 wm1_50; wm1_50 = lambert_wm1(z50); std::cout.precision(std::numeric_limits::max_digits10); // 50 decimal digits. - std::cout << "Reference Lambert W-1 (" << z << ") =\n " + std::cout << "Reference Lambert W-1 (" << z << ") =\n " << wm1_50 << std::endl; std::cout.precision(std::numeric_limits::max_digits10); // 17 decimal digits for double. double wr = static_cast(wm1_50); @@ -204,7 +204,7 @@ Lambert W (10.0000000) = 1.74552800 */ - + // Similar example using cpp_bin_float_quad (128-bit floating-point types). cpp_bin_float_quad zq = 10.; @@ -235,7 +235,7 @@ Lambert W (10.0000000) = 1.74552800 std::cout.precision(std::numeric_limits::digits10); // 1.745528002740699383074301264875389837 std::cout << "lambert_w0(z) cpp_dec_float_50 cast to quad (digits10(" << std::numeric_limits::digits10 << " ) = " << static_cast(r) << std::endl; // 1.74552800274069938307430126487539 - std::cout.precision(std::numeric_limits::digits10 + 1); // + std::cout.precision(std::numeric_limits::digits10 + 1); // std::cout << "lambert_w0(z) cpp_dec_float_50 cast to quad (digits10(" << std::numeric_limits::digits10 << " ) = " << static_cast(r) << std::endl; // 1.74552800274069938307430126487539 @@ -259,11 +259,6 @@ Lambert W (10.0000000) = 1.74552800 } } // int main() - /* - - - - - */ +