Ticket #8711: boost_multiprecision_error_demo.cpp

File boost_multiprecision_error_demo.cpp, 1.4 KB (added by Jan Bouwer <JBouwer@…>, 9 years ago)

A demonstration of the error.

Line 
1//
2// boost_multiprecision_error_demo.cpp
3//
4// Created by Jan Bouwer on 19/6/13.
5
6
7#include <cassert>
8#include <cstdint>
9#include <limits>
10#include <boost/multiprecision/cpp_int.hpp>
11
12
13template<typename T, class I>
14void test_boost_multiprecision()
15{
16 T negMin = std::numeric_limits<T>::min();
17 I test1(negMin), test2( negMin + 1 );
18 --test2;
19
20 assert( test1 == test2 ); // This fails on my platform for T = long
21 assert( test1 != 0 );
22 assert( test1 == negMin );
23 assert( test2 != 0 );
24 assert( test2 == negMin ); // This fails on my platform for T = long
25}
26
27int main(int argc, const char * argv[])
28{
29 test_boost_multiprecision<int64_t, boost::multiprecision::checked_cpp_int>(); // Fails on my platform
30 test_boost_multiprecision<int32_t, boost::multiprecision::checked_cpp_int>(); // Pass
31 test_boost_multiprecision<int16_t, boost::multiprecision::checked_cpp_int>(); // Pass
32
33 test_boost_multiprecision<long, boost::multiprecision::cpp_int>(); // Fail on my platform
34
35 // The following hold for my platform: x86_64-apple-darwin12.4.0,
36 // using: Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
37 // with: -std=c++11 -stdlib=libc++
38 // static_assert(std::numeric_limits<long long>::min() == std::numeric_limits<int64_t>::min(), "Ok");
39 // static_assert(std::numeric_limits<long>::min() == std::numeric_limits<int64_t>::min(), "Ok");
40}