Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / test_cpp_int_lit.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 //  Copyright 2013 John Maddock. Distributed under the Boost
3 //  Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/multiprecision/cpp_int.hpp>
7 #include "test.hpp"
8
9 #if !(BOOST_WORKAROUND(BOOST_MSVC, <= 1900) && defined(CI_SUPPRESS_KNOWN_ISSUES)) && defined(BOOST_MP_USER_DEFINED_LITERALS)
10
11 using namespace boost::multiprecision;
12
13 template <class T>
14 void test_literal(T val, const char* p)
15 {
16    BOOST_CHECK_EQUAL(val, cpp_int(p));
17 }
18
19 #define TEST_LITERAL(x)                                      \
20    {                                                         \
21       constexpr auto val1       = BOOST_JOIN(x, _cppi);      \
22       constexpr int1024_t val2  = BOOST_JOIN(x, _cppi1024);  \
23       constexpr auto      val3  = BOOST_JOIN(x, _cppui);     \
24       constexpr uint1024_t val4 = BOOST_JOIN(x, _cppui1024); \
25       test_literal(val1, BOOST_STRINGIZE(x));                \
26       test_literal(val2, BOOST_STRINGIZE(x));                \
27       test_literal(val3, BOOST_STRINGIZE(x));                \
28       test_literal(val4, BOOST_STRINGIZE(x));                \
29       /* Negative values: */                                 \
30       constexpr auto val5      = -BOOST_JOIN(x, _cppi);      \
31       constexpr int1024_t val6 = -BOOST_JOIN(x, _cppi1024);  \
32       constexpr auto      val7 = -val1;                      \
33       constexpr int1024_t val8 = -val2;                      \
34       BOOST_CHECK_EQUAL(val5, -cpp_int(val1));               \
35       BOOST_CHECK_EQUAL(val6, -cpp_int(val1));               \
36       BOOST_CHECK_EQUAL(val7, -cpp_int(val1));               \
37       BOOST_CHECK_EQUAL(val8, -cpp_int(val1));               \
38    }
39
40 int main()
41 {
42    using namespace boost::multiprecision::literals;
43    TEST_LITERAL(0x0);
44    TEST_LITERAL(0x00000);
45    TEST_LITERAL(0x10000000);
46    TEST_LITERAL(0x1234500000000123450000000123345000678000000456000000567000000fefabc00000000000000);
47    return boost::report_errors();
48 }
49
50 #else
51
52 int main() { return 0; }
53
54 #endif