Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards


//  (C) Copyright Nick Thompson 2020.
//  Use, modification and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at
// Deliberately contains some unicode characters:
// boost-no-inspect

#include <iostream>
#include <boost/math/tools/ulps_plot.hpp>
#include <boost/core/demangle.hpp>
#include <boost/math/special_functions/airy.hpp>

using boost::math::tools::ulps_plot;

int main() {
    using PreciseReal = long double;
    using CoarseReal = float;

    typedef boost::math::policies::policy<
      boost::math::policies::promote_double<false> >

    auto ai_coarse = [](CoarseReal x) {
        return boost::math::airy_ai<CoarseReal>(x, no_promote_policy());
    auto ai_precise = [](PreciseReal x) {
        return boost::math::airy_ai<PreciseReal>(x, no_promote_policy());

    std::string filename = "airy_ai_" + boost::core::demangle(typeid(CoarseReal).name()) + ".svg";
    int samples = 10000;
    // How many pixels wide do you want your .svg?
    int width = 700;
    // Near a root, we have unbounded relative error. So for functions with roots, we define an ULP clip:
    PreciseReal clip = 2.5;
    // Should we perturb the abscissas? i.e., should we compute the high precision function f at x,
    // and the low precision function at the nearest representable x̂ to x?
    // Or should we compute both the high precision and low precision function at a low precision representable x̂?
    bool perturb_abscissas = false;
    auto plot = ulps_plot<decltype(ai_precise), PreciseReal, CoarseReal>(ai_precise, CoarseReal(-3), CoarseReal(3), samples, perturb_abscissas);
    // Note the argument chaining:
    // Sometimes it's useful to set a title, but in many cases it's more useful to just use a caption.
    //std::string title = "Airy Ai ULP plot at " + boost::core::demangle(typeid(CoarseReal).name()) + " precision";
    // You can write the plot to a stream:
    //std::cout << plot;
    // Or to a file:

    // Don't like the default dark theme?
    filename =  "airy_ai_" + boost::core::demangle(typeid(CoarseReal).name()) + "_white.svg";

    // Don't like the envelope?
    filename =  "airy_ai_" + boost::core::demangle(typeid(CoarseReal).name()) + "_white_no_envelope.svg";