• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////
2 //  Copyright 2019 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_dec_float.hpp>
7 #include <boost/multiprecision/cpp_int.hpp>
8 #include "test.hpp"
9 
10 using namespace boost::multiprecision;
11 
12 template <class B, expression_template_option ET, class T>
check_type_is_number(const number<B,ET> & v,T t)13 void check_type_is_number(const number<B, ET>& v, T t)
14 {
15    BOOST_CHECK_EQUAL(v, t);
16 }
17 
18 template <class T, class U>
check_type_is_number(const T &,U)19 void check_type_is_number(const T&, U)
20 {
21    BOOST_STATIC_ASSERT_MSG(sizeof(T) == 1, "Oooops we appear to have an expression template when we should not have done so!");
22 }
23 
main()24 int main()
25 {
26 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
27    cpp_dec_float_50 a(1), b(2), c(3);
28    check_type_is_number(-cpp_dec_float_50(3), -3);
29    check_type_is_number(a + cpp_dec_float_50(3), 4);
30    check_type_is_number(a - cpp_dec_float_50(3), -2);
31    check_type_is_number(a * cpp_dec_float_50(3), 3);
32    check_type_is_number(c / cpp_dec_float_50(3), 1);
33 
34    check_type_is_number(cpp_dec_float_50(3) + a, 4);
35    check_type_is_number(cpp_dec_float_50(3) - a, 2);
36    check_type_is_number(cpp_dec_float_50(3) * a, 3);
37    check_type_is_number(cpp_dec_float_50(3) / a, 3);
38 
39    check_type_is_number(3 + cpp_dec_float_50(3), 6);
40    check_type_is_number(3 - cpp_dec_float_50(3), 0);
41    check_type_is_number(3 * cpp_dec_float_50(3), 9);
42    check_type_is_number(3 / cpp_dec_float_50(3), 1);
43 
44    check_type_is_number(cpp_dec_float_50(3) + 3, 6);
45    check_type_is_number(cpp_dec_float_50(3) - 3, 0);
46    check_type_is_number(cpp_dec_float_50(3) * 3, 9);
47    check_type_is_number(cpp_dec_float_50(3) / 3, 1);
48 
49    check_type_is_number(-cpp_int(2), -2);
50    check_type_is_number(~cpp_int(2), -3);
51    check_type_is_number(cpp_int(2) % 3, 2);
52    check_type_is_number(2 % cpp_int(3), 2);
53    check_type_is_number(2 | cpp_int(3), 2|3);
54    check_type_is_number(cpp_int(3)|2, 2|3);
55    check_type_is_number(2 & cpp_int(3), 2&3);
56    check_type_is_number(cpp_int(3)&2, 2&3);
57    check_type_is_number(2 ^ cpp_int(3), 2^3);
58    check_type_is_number(cpp_int(3)^2, 2^3);
59    check_type_is_number(cpp_int(1) << 4, 1 << 4);
60    check_type_is_number(cpp_int(4) >> 1, 2);
61 
62    check_type_is_number(asin(cpp_dec_float_50(0)), 0);
63    check_type_is_number(pow(cpp_dec_float_50(2), 2), 4);
64    check_type_is_number(pow(cpp_dec_float_50(2), b), 4);
65    check_type_is_number(pow(2, cpp_dec_float_50(2)), 4);
66    check_type_is_number(pow(b, cpp_dec_float_50(2)), 4);
67    check_type_is_number(pow(cpp_dec_float_50(2), cpp_dec_float_50(2)), 4);
68 #endif
69    return boost::report_errors();
70 }
71