Skip to content

Commit

Permalink
Merge pull request #1138 from boostorg/rational_macros
Browse files Browse the repository at this point in the history
Add guards to user configurable macro definitions
  • Loading branch information
mborland authored May 22, 2024
2 parents 52be1ad + 7d85d73 commit 3561273
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
62 changes: 41 additions & 21 deletions include/boost/math/tools/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,42 +365,62 @@ struct non_type {};
#endif

//
// Tune performance options for specific compilers:
// Tune performance options for specific compilers,
// but check at each step that nothing has been previously defined by the user first
//
#ifdef _MSC_VER
# define BOOST_MATH_POLY_METHOD 2
# ifndef BOOST_MATH_POLY_METHOD
# define BOOST_MATH_POLY_METHOD 2
# endif
#if _MSC_VER <= 1900
# define BOOST_MATH_RATIONAL_METHOD 1
# ifndef BOOST_MATH_POLY_METHOD
# define BOOST_MATH_RATIONAL_METHOD 1
# endif
#else
# define BOOST_MATH_RATIONAL_METHOD 2
# ifndef BOOST_MATH_RATIONAL_METHOD
# define BOOST_MATH_RATIONAL_METHOD 2
# endif
#endif
#if _MSC_VER > 1900
# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
# ifndef BOOST_MATH_INT_TABLE_TYPE
# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
# endif
# ifndef BOOST_MATH_INT_VALUE_SUFFIX
# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
# endif
#endif

#elif defined(__INTEL_COMPILER)
# define BOOST_MATH_POLY_METHOD 2
# define BOOST_MATH_RATIONAL_METHOD 1
# ifndef BOOST_MATH_POLY_METHOD
# define BOOST_MATH_POLY_METHOD 2
# endif
# ifndef BOOST_MATH_RATIONAL_METHOD
# define BOOST_MATH_RATIONAL_METHOD 1
# endif

#elif defined(__GNUC__)
#if __GNUC__ < 4
# define BOOST_MATH_POLY_METHOD 3
# define BOOST_MATH_RATIONAL_METHOD 3
# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
#else
# define BOOST_MATH_POLY_METHOD 3
# define BOOST_MATH_RATIONAL_METHOD 3
#endif
# ifndef BOOST_MATH_POLY_METHOD
# define BOOST_MATH_POLY_METHOD 3
# endif
# ifndef BOOST_MATH_RATIONAL_METHOD
# define BOOST_MATH_RATIONAL_METHOD 3
# endif

#elif defined(__clang__)

#if __clang__ > 6
# define BOOST_MATH_POLY_METHOD 3
# define BOOST_MATH_RATIONAL_METHOD 3
# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
# ifndef BOOST_MATH_POLY_METHOD
# define BOOST_MATH_POLY_METHOD 3
# endif
# ifndef BOOST_MATH_RATIONAL_METHOD
# define BOOST_MATH_RATIONAL_METHOD 3
# endif
# ifndef BOOST_MATH_INT_TABLE_TYPE
# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT
# endif
# ifndef BOOST_MATH_INT_VALUE_SUFFIX
# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L
# endif
#endif

#endif
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ test-suite special_fun :
[ run git_issue_961.cpp ]
[ run git_issue_1006.cpp ]
[ run git_issue_184.cpp ]
[ run git_issue_1137.cpp ]
[ run special_functions_test.cpp ../../test/build//boost_unit_test_framework ]
[ run test_airy.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ]
[ run test_bessel_j.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ]
Expand Down
19 changes: 19 additions & 0 deletions test/git_issue_1137.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Matt Borland 2024.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See: https://github.com/boostorg/math/issues/1137

#define BOOST_MATH_POLY_METHOD 0
#define BOOST_MATH_RATIONAL_METHOD 0

#include <boost/math/tools/config.hpp>

int main()
{
static_assert(BOOST_MATH_POLY_METHOD == 0, "User defined as 0");
static_assert(BOOST_MATH_RATIONAL_METHOD == 0, "User defined as 0");

return 0;
}

0 comments on commit 3561273

Please sign in to comment.