// (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::html_printer printer(os); printer << "\n\n" << std::endl; printer << "" << std::endl; printer << "

Synopsis

\nSample HTML output for various number types, these are then styled in bold, and various (somewhat untasteful!) colors just because we can, and to check that our markup generation is working correctly.\n"; printer << "

Basic Integers Values:

\n" << boost::math::tools::full_styling; int ival = 0; printer << ""; printer.stream() << "\n"; ival = -23; printer.stream() << "\n"; ival = 23; printer.stream() << std::dec << "\n"; printer.stream() << std::dec << "\n
ValueBaseResult
" << ival << "default"; printer << ival << "
" << ival << "default"; printer << ival << "
" << ival << "hex"; printer << std::hex << ival << "
" << ival << "oct"; printer << std::oct << ival << "
\n\n" << std::dec; printer << "

Basic Floating Point Values:

\n\n"; double fval = 3; printer << ""; printer.stream() << "\n"; fval = 3.14; printer.stream() << "\n"; fval = -1.2345678765e-24; printer.stream() << "\n"; printer.stream() << "\n"; printer.stream() << "\n"; printer.stream() << "\n"; printer.stream() << "\n"; printer.stream() << "\n" << boost::math::tools::multiply_times << std::defaultfloat; // Infinities: fval = std::numeric_limits::infinity(); printer.stream() << "\n"; fval = -std::numeric_limits::infinity(); printer.stream() << "\n"; // NaN's: fval = std::numeric_limits::quiet_NaN(); printer.stream() << "\n"; // Zeros: fval = 0; printer.stream() << "\n"; fval = -fval; printer.stream() << "\n"; printer << "
ValuePrecisionFormatResult
" << fval << "defaultdefault"; printer << fval << "
" << fval << "defaultdefault"; printer << fval << "
" << fval << "defaultdefault"; printer << fval << "
" << fval << "3scientific"; printer << std::setprecision(3) << std::scientific << fval << "
" << fval << "defaultmultiply_x"; printer << boost::math::tools::multiply_x << fval << "
" << fval << "3scientific + multiply_x"; printer << std::setprecision(3) << std::scientific << fval << "
" << fval << "defaultmultiply_dot"; printer << boost::math::tools::multiply_dot << fval << "
" << fval << "3scientific + multiply_dot"; printer << std::setprecision(3) << std::scientific << fval << "
" << fval << "defaultdefault"; printer << fval << "
" << fval << "defaultdefault"; printer << fval << "
" << fval << "defaultdefault"; printer << fval << "
" << fval << "defaultdefault"; printer << fval << "
" << fval << "defaultdefault"; printer << fval << "
\n\n" << std::defaultfloat; printer << "

Complex Values:

\n\n"; std::complex cval(3.25, 4.67); printer << ""; printer.stream() << "\n"; cval = 3.14; printer.stream() << "\n"; cval = std::complex(1.23, -1.2345678765e-24); printer.stream() << "\n"; printer.stream() << "\n"; printer.stream() << "\n"; printer.stream() << "\n"; printer.stream() << "\n"; printer.stream() << "\n" << boost::math::tools::multiply_times << boost::math::tools::upright_i; printer << "\n
ValuePrecisionFormatResult
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "3scientific"; printer << std::scientific << std::setprecision(3) << cval << "
" << cval << "12default + slanted_i"; printer << boost::math::tools::slanted_i << std::defaultfloat << std::setprecision(12) << cval << "
" << cval << "12default + doublestruck_i"; printer << boost::math::tools::doublestruck_i << std::defaultfloat << std::setprecision(12) << cval << "
" << cval << "12default + doublestruck_i + multiply_x"; printer << boost::math::tools::doublestruck_i << boost::math::tools::multiply_x << std::defaultfloat << std::setprecision(12) << cval << "
" << cval << "12default + doublestruck_i + multiply_dot"; printer << boost::math::tools::doublestruck_i << std::defaultfloat << std::setprecision(12) << boost::math::tools::multiply_dot << cval << "
\n\n"; printer << "

Complex Special Values:

\n\n"; printer << ""; cval = std::complex(0, 0); printer.stream() << "\n"; printer.stream() << "\n"; cval = std::complex(3.14, 0); printer.stream() << "\n"; printer.stream() << "\n"; cval = std::complex(-3.14, 0); printer.stream() << "\n"; printer.stream() << "\n"; cval = std::complex(0, 25.5); printer.stream() << "\n"; printer.stream() << "\n"; cval = std::complex(0, -25.5); printer.stream() << "\n"; printer.stream() << "\n"; cval = std::complex(std::numeric_limits::infinity(), 0); printer.stream() << "\n"; cval = std::complex(-std::numeric_limits::infinity(), 0); printer.stream() << "\n"; cval = std::complex(25.5, std::numeric_limits::infinity()); printer.stream() << "\n"; cval = std::complex(25.5, -std::numeric_limits::infinity()); printer.stream() << "\n"; cval = std::complex(std::numeric_limits::quiet_NaN(), 0); printer.stream() << "\n"; cval = std::complex(-std::numeric_limits::quiet_NaN(), 0); printer.stream() << "\n"; cval = std::complex(25.5, std::numeric_limits::quiet_NaN()); printer.stream() << "\n"; cval = std::complex(25.5, -std::numeric_limits::quiet_NaN()); printer.stream() << "\n"; cval = std::complex(std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity()); printer.stream() << "\n"; cval = std::complex(-std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity()); printer.stream() << "\n"; cval = std::complex(std::numeric_limits::infinity(), std::numeric_limits::quiet_NaN()); printer.stream() << "\n"; cval = std::complex(std::numeric_limits::infinity(), -std::numeric_limits::quiet_NaN()); printer.stream() << "\n"; printer << "\n
ValuePrecisionFormatResult
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultshow_zero_components"; printer << boost::math::tools::show_zero_components << cval << boost::math::tools::hide_zero_components << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultshow_zero_components"; printer << boost::math::tools::show_zero_components << cval << boost::math::tools::hide_zero_components << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultshow_zero_components"; printer << boost::math::tools::show_zero_components << cval << boost::math::tools::hide_zero_components << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultshow_zero_components"; printer << boost::math::tools::show_zero_components << cval << boost::math::tools::hide_zero_components << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultshow_zero_components"; printer << boost::math::tools::show_zero_components << cval << boost::math::tools::hide_zero_components << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
" << cval << "defaultdefault"; printer << cval << "
\n\n"; printer << "

Rationals:

\n\n"; printer << ""; boost::rational rat(1, 3); printer.stream() << "\n"; rat = -rat; printer.stream() << "\n"; rat *= 345634; rat /= 565; printer.stream() << "\n"; rat = 0; printer.stream() << "\n"; rat = -23; printer.stream() << "\n"; boost::multiprecision::cpp_rational rat2(1); for (unsigned i = 1; i < 20; i += 2) { rat2 *= i; rat2 /= i + 1; } printer.stream() << "\n"; printer << "\n
ValueResult
" << rat << ""; printer << rat << "
" << rat; printer << "" << rat << "
" << rat; printer << "" << rat << "
" << rat; printer << "" << rat << "
" << rat; printer << "" << rat << "
" << rat2; printer << "" << rat2 << "
\n\n"; printer << "

Polynomials:

\n\n"; printer << ""; boost::math::tools::polynomial poly1 = { 2, -3, 4, 5 }; printer << "\n"; boost::math::tools::polynomial poly2 = { 2.4, -34.25, 4.2e-6, -5.34e-67 }; printer << "\n"; boost::math::tools::polynomial > poly3 = { { 2.4, 3.25 }, {-34.25 }, { 0, 4.2e-6 }, { -5.34e-67, 4.65e-20 } }; printer << "\n"; boost::math::tools::polynomial> poly4 = { {2, 3}, {-3, 23}, {4, 56}, {5, 32} }; printer << "\n"; printer << "\n
TypeResult
Integer" << poly1 << "
Float" << poly2 << "
Complex" << poly3 << "
Polynomial" << poly4 << "
\n\n"; printer << "\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; }