Boost C++ Libraries

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

PrevUpHomeNext

Frequently Asked Questions FAQ

  1. I'm a FORTRAN/NAG/SPSS/SAS/Cephes/MathCad/R user and I don't see where the functions like dnorm(mean, sd) are in Boost.Math?
    Nearly all are provided, and many more like mean, skewness, quantiles, complements ... but Boost.Math makes full use of C++, and it looks a bit different. But do not panic! See section on construction and the many examples. Briefly, the distribution is constructed with the parameters (like location and scale) (things after the | in representation like P(X=k|n, p) or ; in a common represention of pdf f(x; μσ2). Functions like pdf, cdf are called with the name of that distribution and the random variate often called x or k. For example, normal my_norm(0, 1); pdf(my_norm, 2.0);
  2. I'm a user of New SAS Functions for Computing Probabilities.
    You will find the interface more familar, but to be able to select a distribution (perhaps using a string) see the Extras/Future Directions section, and /boost/libs/math/dot_net_example/boost_math.cpp for an example that is used to create a C# (C sharp) utility (that you might also find useful): see Statistical Distribution Explorer.
  3. I'm allegic to reading manuals and prefer to learn from examples.
    Fear not - you are not alone! Many examples are available for functions and distributions. Some are referenced directly from the text. Others can be found at \boost_latest_release\libs\math\example. If you are a Visual Studio user, you should be able to create projects from each of these, making sure that the Boost library is in the include directories list.
  4. How do I make sure that the Boost library is in the Visual Studio include directories list?
    You can add an include path, for example, your Boost place /boost-latest_release, for example X:/boost_1_45_0/ if you have a separate partition X for Boost releases. Or you can use an environment variable BOOST_ROOT set to your Boost place, and include that. Visual Studio before 2010 provided Tools, Options, VC++ Directories to control directories: Visual Studio 2010 instead provides property sheets to assist. You may find it convenient to create a new one adding \boost-latest_release; to the existing include items in $(IncludePath).
  5. I'm a FORTRAN/NAG/SPSS/SAS/Cephes/MathCad/R user and I don't see where the properties like mean, median, mode, variance, skewness of distributions are in Boost.Math?
    They are all available (if defined for the parameters with which you constructed the distribution) via Cumulative Distribution Function, Probability Density Function, Quantile, Hazard Function, Cumulative Hazard Function, mean, median, mode, variance, standard deviation, skewness, kurtosis, kurtosis_excess, range and support.
  6. I am a C programmer. Can I user Boost.Math with C?
    Yes you can, including all the special functions, and TR1 functions like isnan. They appear as C functions, by being declared as "extern C".
  7. I am a C# (Basic? F# FORTRAN? Other CLI?) programmer. Can I use Boost.Math with C#? (or ...)?
    Yes you can, including all the special functions, and TR1 functions like isnan. But you must build the Boost.Math as a dynamic library (.dll) and compile with the /CLI option. See the boost/math/dot_net_example folder which contains an example that builds a simple statistical distribution app with a GUI. See Statistical Distribution Explorer
  8. What these "policies" things for?
    Policies are a powerful (if necessarily complex) fine-grain mechanism that allow you to customise the behaviour of the Boost.Math library according to your precise needs. See Policies. But if, very probably, the default behaviour suits you, you don't need to know more.
  9. I am a C user and expect to see global C-style::errno set for overflow/errors etc?
    You can achieve what you want - see error handling policies and user error handling and many examples.
  10. I am a C user and expect to silently return a max value for overflow?
    You (and C++ users too) can return whatever you want on overflow - see overflow_error and error handling policies and several examples.
  11. I don't want any error message for overflow etc?
    You can control exactly what happens for all the abnormal conditions, including the values returned. See domain_error, overflow_error error handling policies user error handling etc and examples.
  12. My environment doesn't allow and/or I don't want exceptions. Can I still user Boost.Math?
    Yes but you must customise the error handling: see user error handling and changing policies defaults .
  13. The docs are several hundreds of pages long! Can I read the docs off-line or on paper?
    Yes - you can download the Boost current release of most documentation as a zip of pdfs (including Boost.Math) from Sourceforge, for example https://sourceforge.net/projects/boost/files/boost-docs/1.45.0/boost_pdf_1_45_0.tar.gz/download. And you can print any pages you need (or even print all pages - but be warned that there are several hundred!). Both html and pdf versions are highly hyperlinked. The entire Boost.Math pdf can be searched with Adobe Reader, Edit, Find ... This can often find what you seek, a partial substitute for a full index.
  14. I want a compact version for an embedded application. Can I use float precision?
    Yes - by selecting RealType template parameter as float: for example normal_distribution<float> your_normal(mean, sd); (But double may still be used internally, so space saving may be less that you hope for). You can also change the promotion policy, but accuracy might be much reduced.
  15. I seem to get somewhat different results compared to other programs. Why? We hope Boost.Math to be more accurate: our priority is accuracy (over speed). See the section on accuracy. But for evaluations that require iterations there are parameters which can change the required accuracy (see Policies). You might be able to squeeze a little more (or less) accuracy at the cost of runtime.
  16. Will my program run more slowly compared to other math functions and statistical libraries? Probably, thought not always, and not by too much: our priority is accuracy. For most functions, making sure you have the latest compiler version with all optimisations switched on is the key to speed. For evaluations that require iteration, you may be able to gain a little more speed at the expense of accuracy. See detailed suggestions and results on performance.
  17. How do I handle infinity and NaNs portably?
    See nonfinite fp_facets for Facets for Floating-Point Infinities and NaNs.
  18. Where are the pre-built libraries?
    Good news - you probably don't need any! - just #include <boost/math/distribution_you_want>. But in the unlikely event that you do, see building libraries.
  19. I don't see the function or distribution that I want.
    You could try an email to ask the authors - but no promises!
  20. I need more decimal digits for values/computations.
    You can use Boost.Math with Boost.Multiprecision: typically cpp_dec_float is a useful user-defined type to provide a fixed number of decimal digits, usually 50 or 100.
  21. Why can't I write something really simple like cpp_int one(1); cpp_dec_float_50 two(2); one * two; Because cpp_int might be bigger than cpp_dec_float can hold, so you must make an explicit conversion. See mixed multiprecision arithmetic and conversion.

PrevUpHomeNext