]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | |
2 | // (C) Copyright Nick Thompson 2020. | |
3 | // (C) Copyright John Maddock 2020. | |
4 | // Use, modification and distribution are subject to the | |
5 | // Boost Software License, Version 1.0. (See accompanying file | |
6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | #include <iostream> | |
8 | #include <boost/math/tools/ulps_plot.hpp> | |
9 | #include <boost/core/demangle.hpp> | |
10 | #include <boost/multiprecision/mpfr.hpp> | |
11 | #include <boost/multiprecision/cpp_bin_float.hpp> | |
12 | ||
13 | using boost::math::tools::ulps_plot; | |
14 | ||
15 | int main() { | |
16 | using PreciseReal = boost::multiprecision::mpfr_float_100; | |
17 | using CoarseReal = boost::multiprecision::cpp_bin_float_50; | |
18 | ||
19 | typedef boost::math::policies::policy< | |
20 | boost::math::policies::promote_float<false>, | |
21 | boost::math::policies::promote_double<false> > | |
22 | no_promote_policy; | |
23 | ||
24 | auto ai_coarse = [](CoarseReal const& x)->CoarseReal { | |
25 | return tgamma(x); | |
26 | }; | |
27 | auto ai_precise = [](PreciseReal const& x)->PreciseReal { | |
28 | return tgamma(x); | |
29 | }; | |
30 | ||
31 | std::string filename = "cpp_bin_float_tgamma.svg"; | |
32 | int samples = 100000; | |
33 | // How many pixels wide do you want your .svg? | |
34 | int width = 700; | |
35 | // Near a root, we have unbounded relative error. So for functions with roots, we define an ULP clip: | |
36 | PreciseReal clip = 400; | |
37 | // Should we perturb the abscissas? | |
38 | bool perturb_abscissas = false; | |
39 | auto plot = ulps_plot<decltype(ai_precise), PreciseReal, CoarseReal>(ai_precise, CoarseReal(-20), CoarseReal(200), samples, perturb_abscissas); | |
40 | // Note the argument chaining: | |
41 | plot.clip(clip).width(width); | |
42 | plot.background_color("white").font_color("black"); | |
43 | // Sometimes it's useful to set a title, but in many cases it's more useful to just use a caption. | |
44 | //std::string title = "Airy Ai ULP plot at " + boost::core::demangle(typeid(CoarseReal).name()) + " precision"; | |
45 | //plot.title(title); | |
46 | plot.vertical_lines(6); | |
47 | plot.add_fn(ai_coarse); | |
48 | // You can write the plot to a stream: | |
49 | //std::cout << plot; | |
50 | // Or to a file: | |
51 | plot.write(filename); | |
52 | } |