Skip to content

Commit 74f9437

Browse files
added CMake option USE_BOOST_INT128 to use a Boost.Multiprecision 128-bit integer for MathLib:big{u}int (danmar#7028)
Co-authored-by: chrchr-github <chrchr-github@users.noreply.github.com>
1 parent 773663f commit 74f9437

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ if(MSVC)
44
endif()
55
project(Cppcheck VERSION 2.16.99 LANGUAGES CXX)
66

7+
include(cmake/options.cmake)
8+
79
include(cmake/cxx11.cmake)
810
use_cxx11()
911
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -14,7 +16,6 @@ include(GNUInstallDirs)
1416

1517
include(cmake/compilerCheck.cmake)
1618
include(cmake/versions.cmake)
17-
include(cmake/options.cmake)
1819
include(cmake/findDependencies.cmake)
1920
include(cmake/compileroptions.cmake)
2021
include(cmake/compilerDefinitions.cmake)

cmake/compilerDefinitions.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ endif()
3535

3636
if(Boost_FOUND)
3737
add_definitions(-DHAVE_BOOST)
38+
if(USE_BOOST_INT128)
39+
add_definitions(-DHAVE_BOOST_INT128)
40+
endif()
3841
endif()
3942

4043
if(ENABLE_CHECK_INTERNAL)

cmake/cxx11.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ macro(use_cxx11)
33
if(MSVC AND USE_QT6)
44
# CMAKE_CXX_STANDARD 17 was added in CMake 3.8
55
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use")
6+
elseif(USE_BOOST AND USE_BOOST_INT128)
7+
# Boost.Math requires C++14
8+
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to use")
69
else()
710
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
811
endif()

cmake/options.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ endif()
6767
option(CPPCHK_GLIBCXX_DEBUG "Usage of STL debug checks in Debug build" ON)
6868
option(DISALLOW_THREAD_EXECUTOR "Disallow usage of ThreadExecutor for -j" OFF)
6969
option(USE_BOOST "Usage of Boost" OFF)
70+
option(USE_BOOST_INT128 "Usage of Boost.Multiprecision 128-bit integer for Mathlib" OFF)
7071
option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF)
7172

7273
if(DISALLOW_THREAD_EXECUTOR AND WIN32)

cmake/printInfo.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ if(USE_BOOST)
9595
message(STATUS "Boost_FOUND = ${Boost_FOUND}")
9696
message(STATUS "Boost_VERSION_STRING = ${Boost_VERSION_STRING}")
9797
message(STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}")
98+
message(STATUS "USE_BOOST_INT128 = ${USE_BOOST_INT128}")
99+
message(STATUS)
98100
endif()
99101
message(STATUS "USE_LIBCXX = ${USE_LIBCXX}")
100102
message(STATUS)

lib/mathlib.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include <cstdint>
2727
#include <string>
2828

29+
#if defined(HAVE_BOOST) && defined(HAVE_BOOST_INT128)
30+
#include <boost/multiprecision/cpp_int.hpp>
31+
#endif
32+
2933
/// @addtogroup Core
3034
/// @{
3135

@@ -35,6 +39,14 @@ class CPPCHECKLIB MathLib {
3539
friend class TestMathLib;
3640

3741
public:
42+
#if defined(HAVE_BOOST) && defined(HAVE_BOOST_INT128)
43+
using bigint = boost::multiprecision::int128_t;
44+
using biguint = boost::multiprecision::uint128_t;
45+
#else
46+
using bigint = long long;
47+
using biguint = unsigned long long;
48+
#endif
49+
3850
/** @brief value class */
3951
class value {
4052
private:
@@ -66,8 +78,6 @@ class CPPCHECKLIB MathLib {
6678
value shiftRight(const value &v) const;
6779
};
6880

69-
using bigint = long long;
70-
using biguint = unsigned long long;
7181
static const int bigint_bits;
7282

7383
/** @brief for conversion of numeric literals - for atoi-like conversions please use strToInt() */

0 commit comments

Comments
 (0)