// (C) Copyright John Maddock 2019. // 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 #include #include #include #include #include void print(std::ostream& os) { boost::math::tools::docbook_printer printer(os); printer << "[template integer_formatting_examples[]\n"; int ival = 0; printer << "[table:integer_fmt_examples Basic Integer Values\n[[Value][Base][Result]]\n"; printer.stream() << "[[" << ival << "][default]['''"; printer << ival << "''']]\n"; ival = -23; printer.stream() << "[[" << ival << "][default]['''"; printer << ival << "''']]\n"; ival = 23; printer.stream() << std::dec << "[[" << ival << "][hex]['''"; printer << std::hex << ival << "''']]\n"; printer.stream() << std::dec << "[[" << ival << "][oct]['''"; printer << std::oct << ival << "''']]\n]\n]\n" << std::dec; printer << "[template float_formatting_examples[]\n"; double fval = 3; printer << "[table:float_fmt_examples Basic Float Values\n[[Value][Precision][Format][Result]]"; printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; fval = 3.14; printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; fval = -1.2345678765e-24; printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; printer.stream() << "[[" << fval << "][3][scientific]['''"; printer << std::setprecision(3) << std::scientific << fval << "''']]\n"; printer.stream() << "[[" << fval << "][3][scientific + multiply_x]['''"; printer << std::setprecision(3) << std::scientific << boost::math::tools::multiply_x << fval << "''']]\n"; printer.stream() << "[[" << fval << "][3][scientific + multiply_dot]['''"; printer << std::setprecision(3) << std::scientific << boost::math::tools::multiply_dot << fval << "''']]\n" << boost::math::tools::multiply_times << std::defaultfloat; fval = 0; printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; fval = -fval; printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; fval = std::numeric_limits::infinity(); printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; fval = -std::numeric_limits::infinity(); printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; fval = std::numeric_limits::quiet_NaN(); printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; fval = -std::numeric_limits::quiet_NaN(); printer.stream() << "[[" << fval << "][default][default]['''"; printer << fval << "''']]\n"; printer << "]\n]\n" << std::defaultfloat; printer << "[template complex_formatting_examples[]\n"; std::complex cval(3.25, 4.67); printer << "[table:complex_fmt_examples Basic Complex Values\n[[Value][Precision][Format][Result]]"; printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = 3.14; printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = std::complex(1.23, -1.2345678765e-24); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; printer.stream() << "[[" << cval << "][3][scientific]['''"; printer << std::scientific << std::setprecision(3) << cval << "''']]\n"; printer.stream() << "[[" << cval << "][12][default + slanted_i]['''"; printer << boost::math::tools::slanted_i << std::defaultfloat << std::setprecision(12) << cval << "''']]\n"; printer.stream() << "[[" << cval << "][12][default + doublestruck_i]['''"; printer << boost::math::tools::doublestruck_i << std::defaultfloat << std::setprecision(12) << cval << "''']]\n"; printer.stream() << "[[" << cval << "][12][default + doublestruck_i + multiply_x]['''"; printer << boost::math::tools::doublestruck_i << std::defaultfloat << std::setprecision(12) << boost::math::tools::multiply_x << cval << "''']]\n"; printer.stream() << "[[" << cval << "][12][default + doublestruck_i + multiply_dot]['''"; printer << boost::math::tools::doublestruck_i << std::defaultfloat << std::setprecision(12) << boost::math::tools::multiply_dot << cval << "''']]\n" << boost::math::tools::multiply_times << boost::math::tools::upright_i; printer << "\n]\n]\n"; printer << "[template complex_formatting_examples_2[]\n"; printer << "[table:complex_fmt_examples Complex Special Values\n[[Value][Precision][Format][Result]]"; cval = std::complex(0, 0); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; printer.stream() << "[[" << cval << "][default][show_zero_components]['''"; printer << boost::math::tools::show_zero_components << cval << "''']]\n" << boost::math::tools::hide_zero_components; cval = std::complex(2.5, 0); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; printer.stream() << "[[" << cval << "][default][show_zero_components]['''"; printer << boost::math::tools::show_zero_components << cval << "''']]\n" << boost::math::tools::hide_zero_components; cval = std::complex(-2.5, 0); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; printer.stream() << "[[" << cval << "][default][show_zero_components]['''"; printer << boost::math::tools::show_zero_components << cval << "''']]\n" << boost::math::tools::hide_zero_components; cval = std::complex(0, 3.25); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; printer.stream() << "[[" << cval << "][default][show_zero_components]['''"; printer << boost::math::tools::show_zero_components << cval << "''']]\n" << boost::math::tools::hide_zero_components; cval = std::complex(0, -3.25); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; printer.stream() << "[[" << cval << "][default][show_zero_components]['''"; printer << boost::math::tools::show_zero_components << cval << "''']]\n" << boost::math::tools::hide_zero_components; // Infinites and NaN's: cval = std::complex(std::numeric_limits::infinity(), 2.5); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = std::complex(-std::numeric_limits::infinity(), 2.5); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = std::complex(2.5, std::numeric_limits::infinity()); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = std::complex(2.5, -std::numeric_limits::infinity()); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = std::complex(2.5, std::numeric_limits::quiet_NaN()); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = std::complex(std::numeric_limits::quiet_NaN(), 2.5); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = std::complex(std::numeric_limits::infinity(), std::numeric_limits::quiet_NaN()); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; cval = std::complex(std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity()); printer.stream() << "[[" << cval << "][default][default]['''"; printer << cval << "''']]\n"; printer << "\n]\n]\n"; printer << "[template rational_formatting_examples[]\n"; printer << "[table:rat_fmt_examples Rational Values\n[[Value][Result]]\n"; boost::rational rat(1, 3); printer.stream() << "[[" << rat << "]['''"; printer << rat << "''']]\n"; rat = -rat; printer.stream() << "[[" << rat; printer << "]['''" << rat << "''']]\n"; rat *= 345634; rat /= 565; printer.stream() << "[[" << rat; printer << "]['''" << rat << "''']]\n"; rat = 0; printer.stream() << "[[" << rat; printer << "]['''" << rat << "''']]\n"; rat = -23; printer.stream() << "[[" << rat; printer << "]['''" << rat << "''']]\n"; boost::multiprecision::cpp_rational rat2(1); for (unsigned i = 1; i < 20; i += 2) { rat2 *= i; rat2 /= i + 1; } printer.stream() << "[[" << rat2; printer << "]['''" << rat2 << "''']]\n"; printer << "\n]\n]\n"; printer << "[template polynomial_formatting_examples[]\n"; printer << "[table:poly_fmt_examples Polynomial Values\n[[Kind][Result]]"; boost::math::tools::polynomial poly1 = { 2, -3, 4, 5 }; printer << "[[Integer]['''" << poly1 << "''']]" << std::endl; boost::math::tools::polynomial poly2 = { 2.4, -34.25, 4.2e-6, -5.34e-67 }; printer << "[[Float]['''" << poly2 << "''']]" << std::endl; boost::math::tools::polynomial > poly3 = { { 2.4, 3.25 }, {-34.25 }, { 0, 4.2e-6 }, { -5.34e-67, 4.65e-20 } }; printer << "[[Complex]['''" << poly3 << "''']]" << std::endl; boost::math::tools::polynomial> poly4 = { {2, 3}, {-3, 23}, {4, 56}, {5, 32} }; printer << "[[Rational]['''" << poly4 << "''']]" << std::endl; printer << "\n]\n]\n"; } int main(int argc, const char* argv[]) { if (argc > 1) { std::ofstream ofs(argv[1]); print(ofs); } else print(std::cout); return 0; }