2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Get examples working with CMake and Standalone

[ci skip]
This commit is contained in:
Matt Borland
2021-03-27 14:41:59 +03:00
parent 860169d71b
commit 2c4c1a04e8
13 changed files with 62 additions and 12 deletions

View File

@@ -41,7 +41,7 @@ if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
endif()
if(BUILD_EXAMPLE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt")
if(BUILD_EXAMPLE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/example/CMakeLists.txt")
add_subdirectory(example)

3
example/CMakeLists.txt Normal file
View File

@@ -0,0 +1,3 @@
file(GLOB SOURCES "*.cpp")
add_library(examples ${SOURCES})
target_compile_features(examples PRIVATE cxx_std_17)

View File

@@ -2,17 +2,29 @@
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <cmath>
#include <iostream>
#include <iomanip>
#include <boost/math/tools/agm.hpp>
#include <boost/math/constants/constants.hpp>
#ifndef BOOST_MATH_STANDALONE
#include <boost/multiprecision/cpp_bin_float.hpp>
#endif
// This example computes the lemniscate constant to high precision using the agm:
using boost::math::tools::agm;
using boost::math::constants::pi;
int main() {
using std::sqrt;
#ifndef BOOST_MATH_STANDALONE
using Real = boost::multiprecision::cpp_bin_float_100;
#else
using Real = long double;
#endif
Real G = agm(sqrt(Real(2)), Real(1));
std::cout << std::setprecision(std::numeric_limits<Real>::max_digits10);
std::cout << " Gauss's lemniscate constant = " << pi<Real>()/G << "\n";

View File

@@ -38,7 +38,7 @@ int main()
std::cout << "The exact integral is " << Q_expected << std::endl;
// For an integral over the entire real line, use sinh-sinh quadrature:
sinh_sinh<double> sinh_integrator(tol, 10);
sinh_sinh<double> sinh_integrator(10);
auto f2 = [](double t) { return cos(t)/cosh(t);};
Q = sinh_integrator.integrate(f2);
Q_expected = pi<double>()/cosh(half_pi<double>());
@@ -47,7 +47,7 @@ int main()
// For half-infinite intervals, use exp-sinh.
// Endpoint singularities are handled well:
exp_sinh<double> exp_integrator(tol, 10);
exp_sinh<double> exp_integrator(10);
auto f3 = [](double t) { return exp(-t)/sqrt(t); };
Q = exp_integrator.integrate(f3, 0, std::numeric_limits<double>::infinity());
Q_expected = root_pi<double>();

View File

@@ -13,7 +13,12 @@
#include <iomanip>
#include <iostream>
#include <limits>
#include <boost/detail/endian.hpp>
#ifndef BOOST_MATH_STANDALONE
#include <boost/endian.hpp>
#else
#include <boost/math/tools/config.hpp>
#endif
//------------------------------------------------------------------------------

View File

@@ -52,6 +52,9 @@ int main()
cout << "diff = " << diff
<< ", variance = " << variance << ", ratio = " << diff/variance
<< ", alpha = " << alpha << ", beta = " << beta << endl;
/* inverse_chi_square_df_estimator is not in the code base anymore?
using boost::math::detail::inverse_chi_square_df_estimator;
using boost::math::policies::default_policy;
inverse_chi_square_df_estimator<> a_df(alpha, beta, variance, diff);
@@ -62,16 +65,15 @@ int main()
double est_df = a_df(1);
cout << df << " " << a_df(df) << endl;
}
*/
//template <class F, class T, class Tol, class Policy>std::pair<T, T>
// bracket_and_solve_root(F f, const T& guess, T factor, bool rising, Tol tol, std::uintmax_t& max_iter, const Policy& pol)
// TODO: Not implemented
//double df = inverse_chi_squared_distribution<>::find_degrees_of_freedom(diff, alpha, beta, variance, 0);
double df = inverse_chi_squared::find_degrees_of_freedom(diff, alpha, beta, variance, 100);
cout << df << endl;
//cout << df << endl;
}
catch(const std::exception& e)
{ // Always useful to include try & catch blocks because default policies

View File

@@ -27,6 +27,8 @@ http://www3.imperial.ac.uk/pls/portallive/docs/1/7292572.PDF
*/
#ifndef BOOST_MATH_STANDALONE
#include <boost/math/special_functions/lambert_w.hpp>
using boost::math::lambert_w0;
#include <boost/math/special_functions.hpp>
@@ -278,3 +280,4 @@ int main()
//] [/lambert_w_output_1]
*/
#endif // BOOST_MATH_STANDALONE

View File

@@ -8,6 +8,8 @@
// using algorithm of Thomas Luu.
// https://svn.boost.org/trac/boost/ticket/11027
#ifndef BOOST_MATH_STANDALONE
#include <boost/config.hpp> // for BOOST_PLATFORM, BOOST_COMPILER, BOOST_STDLIB ...
#include <boost/version.hpp> // for BOOST_MSVC versions.
#include <boost/cstdint.hpp>
@@ -237,3 +239,5 @@ int main()
//] [/lambert_w_output_1]
*/
#endif // BOOST_MATH_STANDALONE

View File

@@ -17,6 +17,7 @@ the sensible ranges and axes are too different.
One would get too small LambertW0 in top right and W-1 in bottom left.
*/
#ifndef BOOST_MATH_STANDALONE
#include <boost/math/special_functions/lambert_w.hpp>
using boost::math::lambert_w0;
@@ -284,3 +285,5 @@ int main()
//] [/lambert_w_graph_1_output]
*/
#endif // BOOST_MATH_STANDALONE

View File

@@ -2,17 +2,27 @@
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/multiprecision/mpfr.hpp>
#include <iostream>
#include <boost/math/tools/luroth_expansion.hpp>
#include <boost/math/constants/constants.hpp>
#ifndef BOOST_MATH_STANDALONE
#include <boost/multiprecision/mpfr.hpp>
using boost::multiprecision::mpfr_float;
#endif // BOOST_MATH_STANDALONE
using boost::math::constants::pi;
using boost::math::tools::luroth_expansion;
using boost::multiprecision::mpfr_float;
int main() {
#ifndef BOOST_MATH_STANDALONE
using Real = mpfr_float;
mpfr_float::default_precision(1024);
#else
using Real = long double;
#endif
auto luroth = luroth_expansion(pi<Real>());
std::cout << luroth << "\n";
}

View File

@@ -200,13 +200,13 @@ T fifth_noderiv(T x)
cout << "Unable to locate solution in chosen iterations:"
" Current best guess is between " << r.first << " and " << r.second << endl;
}
T distance = float_distance(r.first, r.second);
T distance = boost::math::float_distance(r.first, r.second);
if (distance > 0)
{ //
std::cout << distance << " bits separate the bracketing values." << std::endl;
for (int i = 0; i < distance; i++)
{ // Show all the values within the bracketing values.
std::cout << float_advance(r.first, i) << std::endl;
std::cout << boost::math::float_advance(r.first, i) << std::endl;
}
}
else

View File

@@ -10,6 +10,8 @@
// Example of root finding using Boost.Multiprecision.
#ifndef BOOST_MATH_STANDALONE
#include <boost/math/tools/roots.hpp>
//using boost::math::policies::policy;
//using boost::math::tools::newton_raphson_iterate;
@@ -230,3 +232,5 @@ value = 2, cube root =1.2599210498948731647672106072782283505702514647015
*/
#endif // BOOST_MATH_STANDALONE

View File

@@ -6,6 +6,8 @@
//[special_data_example
#ifndef BOOST_MATH_STANDALONE
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/math/tools/test_data.hpp>
#include <boost/test/included/prg_exec_monitor.hpp>
@@ -82,3 +84,5 @@ int cpp_main(int argc, char*argv [])
}
//]
#endif // BOOST_MATH_STANDALONE