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