Imported Upstream version 1.57.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
10 #ifdef BOOST_MP_USER_DEFINED_LITERALS
11
12
13 using namespace boost::multiprecision;
14
15 template <class T>
16 void test_literal(T val, const char* p)
17 {
18    BOOST_CHECK_EQUAL(val, cpp_int(p));
19 }
20
21 #define TEST_LITERAL(x)\
22 {\
23    constexpr auto val1 = BOOST_JOIN(x, _cppi);\
24    constexpr int1024_t val2 = BOOST_JOIN(x, _cppi1024);\
25    constexpr auto val3 = BOOST_JOIN(x, _cppui);\
26    constexpr uint1024_t val4 = BOOST_JOIN(x, _cppui1024);\
27    test_literal(val1, BOOST_STRINGIZE(x));\
28    test_literal(val2, BOOST_STRINGIZE(x));\
29    test_literal(val3, BOOST_STRINGIZE(x));\
30    test_literal(val4, BOOST_STRINGIZE(x));\
31    /* Negative values: */\
32    constexpr auto val5 = -BOOST_JOIN(x, _cppi);\
33    constexpr int1024_t val6 = -BOOST_JOIN(x, _cppi1024);\
34    constexpr auto val7 = -val1;\
35    constexpr int1024_t val8 = -val2;\
36    BOOST_CHECK_EQUAL(val5, -cpp_int(val1));\
37    BOOST_CHECK_EQUAL(val6, -cpp_int(val1));\
38    BOOST_CHECK_EQUAL(val7, -cpp_int(val1));\
39    BOOST_CHECK_EQUAL(val8, -cpp_int(val1));\
40 }\
41
42 int main()
43 {
44    using namespace boost::multiprecision::literals;
45    TEST_LITERAL(0x0);
46    TEST_LITERAL(0x00000);
47    TEST_LITERAL(0x10000000);
48    TEST_LITERAL(0x1234500000000123450000000123345000678000000456000000567000000fefabc00000000000000);
49    return boost::report_errors();
50 }
51
52 #else
53
54 int main() { return 0; }
55
56
57 #endif