Search code examples
c++boostlong-double

How to disable long double in boost::math?


I have c++ source file, example.cpp, using some boost::math functions.

My boost library is also built.

To disable long double in boost::math, I did the following:

g++ -DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS example.cpp -I<boost_header> -L<boost.*.so>

My question is whether do I need to rebuild boost library with -DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS? Or, in other words, did the boost library differ with and without macro BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS?


Solution

  • Yes, there might be a difference. However, in practice, there will usually not be:

    Boot Math docs: Building a Library

    The first thing you need to ask yourself is "Do I need to build anything at all?" as the bulk of this library is header only: meaning you can use it just by #including the necessary header(s).

    For most simple uses, including a header (or few) is best for compile time and program size.

    Refer to C99 and C++ TR1 C-style Functions for pros and cons of using the TR1 components as opposed to the header only ones.

    The only time you need to build the library is if you want to use the extern "C" functions declared in <boost/math/tr1.hpp>.

    Since tr1.hpp does in fact use the BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS macro, so yes there will probably be a relevant difference.

    In fact from a quick scan it looks like auto-linking (on MSVC) is only caused when the preprocessor condition is not defined. Which implies that building the library is completely unnecessary when the symbol is defined. Try not linking to the library to check that assumption:

    g++ -DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS example.cpp -I<boost_header>
    

    Post Scriptum

    The only use of the define in libs/math/src is in boost_nexttoward and boost_nexttowardf.

    So unless you use these, there should be no issue.

    In all of Boost 1.77 the only libraries that mention these boost/math/tr1.hpp are Multiprecision and Units - but it looks like they took great care to NOT expand macros and never explicitly call the boost_* symbols.

    All in all, you're only looking for direct calls to [boost_]nexttoward[f] in your own code.