857 lines · plain
1// Copyright (c) 2006-7 John Maddock2// Copyright (c) 2021 Matt Borland3// Use, modification and distribution are subject to the4// Boost Software License, Version 1.0. (See accompanying file5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)6 7#ifndef BOOST_MATH_TOOLS_CONFIG_HPP8#define BOOST_MATH_TOOLS_CONFIG_HPP9 10#ifdef _MSC_VER11#pragma once12#endif13 14#ifndef __CUDACC_RTC__15 16#include <boost/math/tools/is_standalone.hpp>17 18// Minimum language standard transition19#ifdef _MSVC_LANG20# if _MSVC_LANG < 201402L21# pragma message("Boost.Math requires C++14");22# endif23# if _MSC_VER == 190024# pragma message("MSVC 14.0 has broken C++14 constexpr support. Support for this compiler will be removed in Boost 1.86")25# endif26#else27# if __cplusplus < 201402L28# warning "Boost.Math requires C++14"29# endif30#endif31 32#ifndef BOOST_MATH_STANDALONE33#include <boost/config.hpp>34 35 36// The following are all defined as standalone macros as well37// If Boost.Config is available just use those definitions because they are more fine-grained38 39// Could be defined in TR140#ifndef BOOST_MATH_PREVENT_MACRO_SUBSTITUTION41# define BOOST_MATH_PREVENT_MACRO_SUBSTITUTION BOOST_PREVENT_MACRO_SUBSTITUTION42#endif43 44#define BOOST_MATH_CXX14_CONSTEXPR BOOST_CXX14_CONSTEXPR45#ifdef BOOST_NO_CXX14_CONSTEXPR46# define BOOST_MATH_NO_CXX14_CONSTEXPR47#endif48 49#define BOOST_MATH_IF_CONSTEXPR BOOST_IF_CONSTEXPR50#ifdef BOOST_NO_CXX17_IF_CONSTEXPR51# define BOOST_MATH_NO_CXX17_IF_CONSTEXPR52#endif53 54#ifdef BOOST_NO_CXX17_HDR_EXECUTION55# define BOOST_MATH_NO_CXX17_HDR_EXECUTION56#endif57 58#ifdef BOOST_HAS_THREADS59# define BOOST_MATH_HAS_THREADS60#endif61#ifdef BOOST_DISABLE_THREADS62# define BOOST_MATH_DISABLE_THREADS63#endif64#ifdef BOOST_NO_CXX11_THREAD_LOCAL65# define BOOST_MATH_NO_CXX11_THREAD_LOCAL66#endif67 68#ifdef BOOST_NO_EXCEPTIONS69# define BOOST_MATH_NO_EXCEPTIONS70#endif71 72#ifdef BOOST_NO_TYPEID73# define BOOST_MATH_NO_TYPEID74#endif75#ifdef BOOST_NO_RTTI76# define BOOST_MATH_NO_RTTI77#endif78 79#define BOOST_MATH_NOINLINE BOOST_NOINLINE80#define BOOST_MATH_FORCEINLINE BOOST_FORCEINLINE81 82#define BOOST_MATH_JOIN(X, Y) BOOST_JOIN(X, Y)83#define BOOST_MATH_STRINGIZE(X) BOOST_STRINGIZE(X)84 85#else // Things from boost/config that are required, and easy to replicate86 87#define BOOST_MATH_PREVENT_MACRO_SUBSTITUTION88#define BOOST_MATH_NO_REAL_CONCEPT_TESTS89#define BOOST_MATH_NO_DISTRIBUTION_CONCEPT_TESTS90#define BOOST_MATH_NO_LEXICAL_CAST91 92// Since Boost.Multiprecision is in active development some tests do not fully cooperate yet.93#define BOOST_MATH_NO_MP_TESTS94 95#if ((__cplusplus > 201400L) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201400L)))96#define BOOST_MATH_CXX14_CONSTEXPR constexpr97#else98#define BOOST_MATH_CXX14_CONSTEXPR99#define BOOST_MATH_NO_CXX14_CONSTEXPR100#endif // BOOST_MATH_CXX14_CONSTEXPR101 102#if ((__cplusplus > 201700L) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201700L)))103#define BOOST_MATH_IF_CONSTEXPR if constexpr104 105// Clang on mac provides the execution header with none of the functionality. TODO: Check back on this106// https://en.cppreference.com/w/cpp/compiler_support "Standardization of Parallelism TS"107# if !__has_include(<execution>) || (defined(__APPLE__) && defined(__clang__))108# define BOOST_MATH_NO_CXX17_HDR_EXECUTION109# endif110#else111# define BOOST_MATH_IF_CONSTEXPR if112# define BOOST_MATH_NO_CXX17_IF_CONSTEXPR113# define BOOST_MATH_NO_CXX17_HDR_EXECUTION114#endif115 116#if (defined(__cpp_lib_gcd_lcm) && (__cpp_lib_gcd_lcm >= 201606L))117#define BOOST_MATH_HAS_CXX17_NUMERIC118#endif119 120#define BOOST_MATH_JOIN(X, Y) BOOST_MATH_DO_JOIN(X, Y)121#define BOOST_MATH_DO_JOIN(X, Y) BOOST_MATH_DO_JOIN2(X,Y)122#define BOOST_MATH_DO_JOIN2(X, Y) X##Y123 124#define BOOST_MATH_STRINGIZE(X) BOOST_MATH_DO_STRINGIZE(X)125#define BOOST_MATH_DO_STRINGIZE(X) #X126 127#ifdef BOOST_MATH_DISABLE_THREADS // No threads, do nothing128// Detect thread support via STL implementation129#elif defined(__has_include)130# if !__has_include(<thread>) || !__has_include(<mutex>) || !__has_include(<future>) || !__has_include(<atomic>)131# define BOOST_MATH_DISABLE_THREADS132# else133# define BOOST_MATH_HAS_THREADS134# endif 135#else136# define BOOST_MATH_HAS_THREADS // The default assumption is that the machine has threads137#endif // Thread Support138 139#ifdef BOOST_MATH_DISABLE_THREADS140# define BOOST_MATH_NO_CXX11_THREAD_LOCAL141#endif // BOOST_MATH_DISABLE_THREADS142 143#ifdef __GNUC__144# if !defined(__EXCEPTIONS) && !defined(BOOST_MATH_NO_EXCEPTIONS)145# define BOOST_MATH_NO_EXCEPTIONS146# endif147 //148 // Make sure we have some std lib headers included so we can detect __GXX_RTTI:149 //150# include <algorithm> // for min and max151# include <limits>152# ifndef __GXX_RTTI153# ifndef BOOST_MATH_NO_TYPEID154# define BOOST_MATH_NO_TYPEID155# endif156# ifndef BOOST_MATH_NO_RTTI157# define BOOST_MATH_NO_RTTI158# endif159# endif160#endif161 162#if !defined(BOOST_MATH_NOINLINE)163# if defined(_MSC_VER)164# define BOOST_MATH_NOINLINE __declspec(noinline)165# elif defined(__GNUC__) && __GNUC__ > 3166 // Clang also defines __GNUC__ (as 4)167# if defined(__CUDACC__)168 // nvcc doesn't always parse __noinline__,169 // see: https://svn.boost.org/trac/boost/ticket/9392170# define BOOST_MATH_NOINLINE __attribute__ ((noinline))171# elif defined(__HIP__)172 // See https://github.com/boostorg/config/issues/392173# define BOOST_MATH_NOINLINE __attribute__ ((noinline))174# else175# define BOOST_MATH_NOINLINE __attribute__ ((__noinline__))176# endif177# else178# define BOOST_MATH_NOINLINE179# endif180#endif181 182#if !defined(BOOST_MATH_FORCEINLINE)183# if defined(_MSC_VER)184# define BOOST_MATH_FORCEINLINE __forceinline185# elif defined(__GNUC__) && __GNUC__ > 3186 // Clang also defines __GNUC__ (as 4)187# define BOOST_MATH_FORCEINLINE inline __attribute__ ((__always_inline__))188# else189# define BOOST_MATH_FORCEINLINE inline190# endif191#endif192 193#endif // BOOST_MATH_STANDALONE194 195// Support compilers with P0024R2 implemented without linking TBB196// https://en.cppreference.com/w/cpp/compiler_support197#if !defined(BOOST_MATH_NO_CXX17_HDR_EXECUTION) && defined(BOOST_MATH_HAS_THREADS)198# define BOOST_MATH_EXEC_COMPATIBLE199#endif200 201// C++23202#if __cplusplus > 202002L || (defined(_MSVC_LANG) &&_MSVC_LANG > 202002L)203# if defined(__GNUC__) && __GNUC__ >= 13204 // libstdc++3 only defines to/from_chars for std::float128_t when one of these defines are set205 // otherwise we're right out of luck...206# if defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128) || defined(_GLIBCXX_HAVE_FLOAT128_MATH)207# include <cstring> // std::strlen is used with from_chars208# include <charconv>209# include <stdfloat>210# define BOOST_MATH_USE_CHARCONV_FOR_CONVERSION211# endif212# endif213#endif214 215#include <algorithm> // for min and max216#include <limits>217#include <cmath>218#include <climits>219#include <cfloat>220 221#include <boost/math/tools/user.hpp>222 223#if (defined(__NetBSD__)\224 || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \225 && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)226//# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS227#endif228 229#if defined(__EMSCRIPTEN__) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)230# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS231#endif232 233#ifdef __IBMCPP__234//235// For reasons I don't understand, the tests with IMB's compiler all236// pass at long double precision, but fail with real_concept, those tests237// are disabled for now. (JM 2012).238#ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS239# define BOOST_MATH_NO_REAL_CONCEPT_TESTS240#endif // BOOST_MATH_NO_REAL_CONCEPT_TESTS241#endif242#ifdef sun243// Any use of __float128 in program startup code causes a segfault (tested JM 2015, Solaris 11).244# define BOOST_MATH_DISABLE_FLOAT128245#endif246#ifdef __HAIKU__247//248// Not sure what's up with the math detection on Haiku, but linking fails with249// float128 code enabled, and we don't have an implementation of __expl, so250// disabling long double functions for now as well.251# define BOOST_MATH_DISABLE_FLOAT128252# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS253#endif254#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)255//256// Darwin's rather strange "double double" is rather hard to257// support, it should be possible given enough effort though...258//259# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS260#endif261#if !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) && (LDBL_MANT_DIG == 106) && (LDBL_MIN_EXP > DBL_MIN_EXP)262//263// Generic catch all case for gcc's "double-double" long double type.264// We do not support this as it's not even remotely IEEE conforming:265//266# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS267#endif268#if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)269//270// Intel compiler prior to version 10 has sporadic problems271// calling the long double overloads of the std lib math functions:272// calling ::powl is OK, but std::pow(long double, long double) 273// may segfault depending upon the value of the arguments passed 274// and the specific Linux distribution.275//276// We'll be conservative and disable long double support for this compiler.277//278// Comment out this #define and try building the tests to determine whether279// your Intel compiler version has this issue or not.280//281# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS282#endif283#if defined(unix) && defined(__INTEL_COMPILER)284//285// Intel compiler has sporadic issues compiling std::fpclassify depending on286// the exact OS version used. Use our own code for this as we know it works287// well on Intel processors:288//289#define BOOST_MATH_DISABLE_STD_FPCLASSIFY290#endif291 292#if defined(_MSC_VER) && !defined(_WIN32_WCE)293 // Better safe than sorry, our tests don't support hardware exceptions:294# define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM)295#endif296 297#ifdef __IBMCPP__298# define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS299#endif300 301#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))302# define BOOST_MATH_USE_C99303#endif304 305#if (defined(__hpux) && !defined(__hppa))306# define BOOST_MATH_USE_C99307#endif308 309#if defined(__GNUC__) && defined(_GLIBCXX_USE_C99)310# define BOOST_MATH_USE_C99311#endif312 313#if defined(_LIBCPP_VERSION) && !defined(_MSC_VER)314# define BOOST_MATH_USE_C99315#endif316 317#if defined(__CYGWIN__) || defined(__HP_aCC) || defined(__INTEL_COMPILER) \318 || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \319 || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\320 || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)321# define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY322#endif323 324#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x590)325 326namespace boost { namespace math { namespace tools { namespace detail {327template <typename T>328struct type {};329 330template <typename T, T n>331struct non_type {};332}}}} // Namespace boost, math tools, detail333 334# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::math::tools::detail::type<t>* = 0335# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::math::tools::detail::type<t>*336# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::math::tools::detail::non_type<t, v>* = 0337# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::math::tools::detail::non_type<t, v>*338 339# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \340 , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)341# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \342 , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)343# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \344 , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)345# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \346 , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)347 348#else349 350// no workaround needed: expand to nothing351 352# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t)353# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t)354# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v)355# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)356 357# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t)358# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t)359# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)360# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v)361 362 363#endif // __SUNPRO_CC364 365#if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT)366// Sun's compiler emits a hard error if a constant underflows,367// as does aCC on PA-RISC, while gcc issues a large number of warnings:368# define BOOST_MATH_SMALL_CONSTANT(x) 0.0369#else370# define BOOST_MATH_SMALL_CONSTANT(x) x371#endif372 373//374// Tune performance options for specific compilers,375// but check at each step that nothing has been previously defined by the user first376//377#ifdef _MSC_VER378# ifndef BOOST_MATH_POLY_METHOD379# define BOOST_MATH_POLY_METHOD 2380# endif381#if _MSC_VER <= 1900382# ifndef BOOST_MATH_POLY_METHOD383# define BOOST_MATH_RATIONAL_METHOD 1384# endif385#else386# ifndef BOOST_MATH_RATIONAL_METHOD387# define BOOST_MATH_RATIONAL_METHOD 2388# endif389#endif390#if _MSC_VER > 1900391# ifndef BOOST_MATH_INT_TABLE_TYPE392# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT393# endif394# ifndef BOOST_MATH_INT_VALUE_SUFFIX395# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L396# endif397#endif398 399#elif defined(__INTEL_COMPILER)400# ifndef BOOST_MATH_POLY_METHOD401# define BOOST_MATH_POLY_METHOD 2402# endif403# ifndef BOOST_MATH_RATIONAL_METHOD404# define BOOST_MATH_RATIONAL_METHOD 1405# endif406 407#elif defined(__GNUC__)408# ifndef BOOST_MATH_POLY_METHOD409# define BOOST_MATH_POLY_METHOD 3410# endif411# ifndef BOOST_MATH_RATIONAL_METHOD412# define BOOST_MATH_RATIONAL_METHOD 3413# endif414 415#elif defined(__clang__)416 417#if __clang__ > 6418# ifndef BOOST_MATH_POLY_METHOD419# define BOOST_MATH_POLY_METHOD 3420# endif421# ifndef BOOST_MATH_RATIONAL_METHOD422# define BOOST_MATH_RATIONAL_METHOD 3423# endif424# ifndef BOOST_MATH_INT_TABLE_TYPE425# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT426# endif427# ifndef BOOST_MATH_INT_VALUE_SUFFIX428# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L429# endif430#endif431 432#endif433 434//435// noexcept support:436//437#include <type_traits>438#define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value)439#define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value)440 441//442// The maximum order of polynomial that will be evaluated 443// via an unrolled specialisation:444//445#ifndef BOOST_MATH_MAX_POLY_ORDER446# define BOOST_MATH_MAX_POLY_ORDER 20447#endif 448//449// Set the method used to evaluate polynomials and rationals:450//451#ifndef BOOST_MATH_POLY_METHOD452# define BOOST_MATH_POLY_METHOD 2453#endif 454#ifndef BOOST_MATH_RATIONAL_METHOD455# define BOOST_MATH_RATIONAL_METHOD 1456#endif 457//458// decide whether to store constants as integers or reals:459//460#ifndef BOOST_MATH_INT_TABLE_TYPE461# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT462#endif463#ifndef BOOST_MATH_INT_VALUE_SUFFIX464# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF465#endif466//467// And then the actual configuration:468//469#if defined(BOOST_MATH_STANDALONE) && defined(_GLIBCXX_USE_FLOAT128) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && !defined(__STRICT_ANSI__) \470 && !defined(BOOST_MATH_DISABLE_FLOAT128) && !defined(BOOST_MATH_USE_FLOAT128)471# define BOOST_MATH_USE_FLOAT128472#elif defined(BOOST_HAS_FLOAT128) && !defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_MATH_DISABLE_FLOAT128)473# define BOOST_MATH_USE_FLOAT128474#endif475#ifdef BOOST_MATH_USE_FLOAT128476//477// Only enable this when the compiler really is GCC as clang and probably 478// intel too don't support __float128 yet :-(479//480# if defined(__INTEL_COMPILER) && defined(__GNUC__)481# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))482# define BOOST_MATH_FLOAT128_TYPE __float128483# endif484# elif defined(__GNUC__)485# define BOOST_MATH_FLOAT128_TYPE __float128486# endif487 488# ifndef BOOST_MATH_FLOAT128_TYPE489# define BOOST_MATH_FLOAT128_TYPE _Quad490# endif491#endif492//493// Check for WinCE with no iostream support:494//495#if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT)496# define BOOST_MATH_NO_LEXICAL_CAST497#endif498 499//500// Helper macro for controlling the FP behaviour:501//502#ifndef BOOST_MATH_CONTROL_FP503# define BOOST_MATH_CONTROL_FP504#endif505//506// Helper macro for using statements:507//508#define BOOST_MATH_STD_USING_CORE \509 using std::abs;\510 using std::acos;\511 using std::cos;\512 using std::fmod;\513 using std::modf;\514 using std::tan;\515 using std::asin;\516 using std::cosh;\517 using std::frexp;\518 using std::pow;\519 using std::tanh;\520 using std::atan;\521 using std::exp;\522 using std::ldexp;\523 using std::sin;\524 using std::atan2;\525 using std::fabs;\526 using std::log;\527 using std::sinh;\528 using std::ceil;\529 using std::floor;\530 using std::log10;\531 using std::sqrt;\532 using std::log2;\533 using std::ilogb;534 535#define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE536 537namespace boost{ namespace math{538namespace tools539{540 541template <class T>542inline T max BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T)543{544 return (std::max)((std::max)(a, b), c);545}546 547template <class T>548inline T max BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T)549{550 return (std::max)((std::max)(a, b), (std::max)(c, d));551}552 553} // namespace tools554 555template <class T>556void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T)557{558}559 560namespace detail{561 562template <class T>563struct is_integer_for_rounding564{565 static constexpr bool value = std::is_integral<T>::value || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer);566};567 568}569 570}} // namespace boost namespace math571 572#ifdef __GLIBC_PREREQ573# if __GLIBC_PREREQ(2,14)574# define BOOST_MATH_HAVE_FIXED_GLIBC575# endif576#endif577 578#if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__))579//580// This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445581// Basically powl and expl can return garbage when the result is small and certain exception flags are set582// on entrance to these functions. This appears to have been fixed in Glibc 2.14 (May 2011).583// Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4584//585 586#include <cfenv>587 588# ifdef FE_ALL_EXCEPT589 590namespace boost{ namespace math{591 namespace detail592 {593 struct fpu_guard594 {595 fpu_guard()596 {597 fegetexceptflag(&m_flags, FE_ALL_EXCEPT);598 feclearexcept(FE_ALL_EXCEPT);599 }600 ~fpu_guard()601 {602 fesetexceptflag(&m_flags, FE_ALL_EXCEPT);603 }604 private:605 fexcept_t m_flags;606 };607 608 } // namespace detail609 }} // namespaces610 611# define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object;612# define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0); 613 614# else615 616# define BOOST_FPU_EXCEPTION_GUARD617# define BOOST_MATH_INSTRUMENT_FPU618 619# endif620 621#else // All other platforms.622# define BOOST_FPU_EXCEPTION_GUARD623# define BOOST_MATH_INSTRUMENT_FPU624#endif625 626#ifdef BOOST_MATH_INSTRUMENT627 628# include <iostream>629# include <iomanip>630# include <typeinfo>631 632# define BOOST_MATH_INSTRUMENT_CODE(x) \633 std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl;634# define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(#name << " = " << name)635 636#else637 638# define BOOST_MATH_INSTRUMENT_CODE(x)639# define BOOST_MATH_INSTRUMENT_VARIABLE(name)640 641#endif642 643//644// Thread local storage:645//646#ifndef BOOST_MATH_DISABLE_THREADS647# define BOOST_MATH_THREAD_LOCAL thread_local648#else649# define BOOST_MATH_THREAD_LOCAL 650#endif651 652//653// Some mingw flavours have issues with thread_local and types with non-trivial destructors654// See https://sourceforge.net/p/mingw-w64/bugs/527/655//656// When running windows-2022 or 2025 we see this issue again with GCC 12 and 14657//658#if (defined(__MINGW32__) && ((__GNUC__ < 9) || (__GNUC__ >= 12)) && !defined(__clang__))659# define BOOST_MATH_NO_THREAD_LOCAL_WITH_NON_TRIVIAL_TYPES660#endif661 662 663//664// Can we have constexpr tables?665//666#if (!defined(BOOST_MATH_NO_CXX14_CONSTEXPR)) || (defined(_MSC_VER) && _MSC_VER >= 1910)667#define BOOST_MATH_HAVE_CONSTEXPR_TABLES668#define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr669#else670#define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION671#endif672 673//674// CUDA support:675//676 677#ifdef __CUDACC__678 679// We have to get our include order correct otherwise you get compilation failures680#include <cuda.h>681#include <cuda_runtime.h>682#include <cuda/std/type_traits>683#include <cuda/std/utility>684#include <cuda/std/cstdint>685#include <cuda/std/array>686#include <cuda/std/tuple>687#include <cuda/std/complex>688 689# define BOOST_MATH_CUDA_ENABLED __host__ __device__690# define BOOST_MATH_HAS_GPU_SUPPORT691 692# ifndef BOOST_MATH_ENABLE_CUDA693# define BOOST_MATH_ENABLE_CUDA694# endif695 696// Device code can not handle exceptions697# ifndef BOOST_MATH_NO_EXCEPTIONS698# define BOOST_MATH_NO_EXCEPTIONS699# endif700 701// We want to use force inline from CUDA instead of the host compiler702# undef BOOST_MATH_FORCEINLINE703# define BOOST_MATH_FORCEINLINE __forceinline__704 705#elif defined(SYCL_LANGUAGE_VERSION)706 707# define BOOST_MATH_SYCL_ENABLED SYCL_EXTERNAL708# define BOOST_MATH_HAS_GPU_SUPPORT709 710# ifndef BOOST_MATH_ENABLE_SYCL711# define BOOST_MATH_ENABLE_SYCL712# endif713 714# ifndef BOOST_MATH_NO_EXCEPTIONS715# define BOOST_MATH_NO_EXCEPTIONS716# endif717 718// spir64 does not support long double719# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS720# define BOOST_MATH_NO_REAL_CONCEPT_TESTS721 722# undef BOOST_MATH_FORCEINLINE723# define BOOST_MATH_FORCEINLINE inline724 725#endif726 727#ifndef BOOST_MATH_CUDA_ENABLED728# define BOOST_MATH_CUDA_ENABLED729#endif730 731#ifndef BOOST_MATH_SYCL_ENABLED732# define BOOST_MATH_SYCL_ENABLED733#endif734 735// Not all functions that allow CUDA allow SYCL (e.g. Recursion is disallowed by SYCL)736# define BOOST_MATH_GPU_ENABLED BOOST_MATH_CUDA_ENABLED BOOST_MATH_SYCL_ENABLED737 738// Additional functions that need replaced/marked up739#ifdef BOOST_MATH_HAS_GPU_SUPPORT740template <class T>741BOOST_MATH_GPU_ENABLED constexpr void gpu_safe_swap(T& a, T& b) { T t(a); a = b; b = t; }742template <class T>743BOOST_MATH_GPU_ENABLED constexpr T gpu_safe_min(const T& a, const T& b) { return a < b ? a : b; }744template <class T>745BOOST_MATH_GPU_ENABLED constexpr T gpu_safe_max(const T& a, const T& b) { return a > b ? a : b; }746 747#define BOOST_MATH_GPU_SAFE_SWAP(a, b) gpu_safe_swap(a, b)748#define BOOST_MATH_GPU_SAFE_MIN(a, b) gpu_safe_min(a, b)749#define BOOST_MATH_GPU_SAFE_MAX(a, b) gpu_safe_max(a, b)750 751#else752 753#define BOOST_MATH_GPU_SAFE_SWAP(a, b) std::swap(a, b)754#define BOOST_MATH_GPU_SAFE_MIN(a, b) (std::min)(a, b)755#define BOOST_MATH_GPU_SAFE_MAX(a, b) (std::max)(a, b)756 757#endif758 759// Static variables are not allowed with CUDA or C++20 modules760// See if we can inline them instead761 762#if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L763# define BOOST_MATH_INLINE_CONSTEXPR inline constexpr764# define BOOST_MATH_STATIC static765# ifndef BOOST_MATH_HAS_GPU_SUPPORT766# define BOOST_MATH_STATIC_LOCAL_VARIABLE static767# else768# define BOOST_MATH_STATIC_LOCAL_VARIABLE769# endif770#else771# ifndef BOOST_MATH_HAS_GPU_SUPPORT772# define BOOST_MATH_INLINE_CONSTEXPR static constexpr773# define BOOST_MATH_STATIC static774# define BOOST_MATH_STATIC_LOCAL_VARIABLE775# else776# define BOOST_MATH_INLINE_CONSTEXPR constexpr777# define BOOST_MATH_STATIC constexpr778# define BOOST_MATH_STATIC_LOCAL_VARIABLE static779# endif780#endif781 782#define BOOST_MATH_FP_NAN FP_NAN783#define BOOST_MATH_FP_INFINITE FP_INFINITE784#define BOOST_MATH_FP_ZERO FP_ZERO785#define BOOST_MATH_FP_SUBNORMAL FP_SUBNORMAL786#define BOOST_MATH_FP_NORMAL FP_NORMAL787 788#else // Special section for CUDA NVRTC to ensure we consume no STL headers789 790#ifndef BOOST_MATH_STANDALONE791# define BOOST_MATH_STANDALONE792#endif793 794#define BOOST_MATH_HAS_NVRTC795#define BOOST_MATH_ENABLE_CUDA796#define BOOST_MATH_HAS_GPU_SUPPORT797 798#define BOOST_MATH_GPU_ENABLED __host__ __device__799#define BOOST_MATH_CUDA_ENABLED __host__ __device__800 801#define BOOST_MATH_STATIC static802#define BOOST_MATH_STATIC_LOCAL_VARIABLE803 804#define BOOST_MATH_NOEXCEPT(T) noexcept(boost::math::is_floating_point_v<T>)805#define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T) 806#define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T) 807#define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T) 808#define BOOST_MATH_BIG_CONSTANT(T, N, V) static_cast<T>(V)809#define BOOST_MATH_FORCEINLINE __forceinline__810#define BOOST_MATH_STD_USING 811#define BOOST_MATH_IF_CONSTEXPR if812#define BOOST_MATH_IS_FLOAT(T) (boost::math::is_floating_point<T>::value)813#define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr814#define BOOST_MATH_NO_EXCEPTIONS815#define BOOST_MATH_PREVENT_MACRO_SUBSTITUTION 816 817// This should be defined to nothing but since it is not specifically a math macro818// we need to undef before proceeding819#ifdef BOOST_FPU_EXCEPTION_GUARD820# undef BOOST_FPU_EXCEPTION_GUARD821#endif822 823#define BOOST_FPU_EXCEPTION_GUARD824 825template <class T>826BOOST_MATH_GPU_ENABLED constexpr void gpu_safe_swap(T& a, T& b) { T t(a); a = b; b = t; }827 828#define BOOST_MATH_GPU_SAFE_SWAP(a, b) gpu_safe_swap(a, b)829#define BOOST_MATH_GPU_SAFE_MIN(a, b) (::min)(a, b)830#define BOOST_MATH_GPU_SAFE_MAX(a, b) (::max)(a, b)831 832#define BOOST_MATH_FP_NAN 0833#define BOOST_MATH_FP_INFINITE 1834#define BOOST_MATH_FP_ZERO 2835#define BOOST_MATH_FP_SUBNORMAL 3836#define BOOST_MATH_FP_NORMAL 4837 838#define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF839#define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT840 841#if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L842# define BOOST_MATH_INLINE_CONSTEXPR inline constexpr843#else844# define BOOST_MATH_INLINE_CONSTEXPR constexpr845#endif846 847#define BOOST_MATH_INSTRUMENT_VARIABLE(x)848#define BOOST_MATH_INSTRUMENT_CODE(x) 849 850#endif // NVRTC851 852#endif // BOOST_MATH_TOOLS_CONFIG_HPP853 854 855 856 857