Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / test_mixed_float.cpp
1 ///////////////////////////////////////////////////////////////
2 //  Copyright 2012 John Maddock. Distributed under the Boost
3 //  Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
5
6 //
7 // Compare arithmetic results using fixed_int to GMP results.
8 //
9
10 #ifdef _MSC_VER
11 #define _SCL_SECURE_NO_WARNINGS
12 #endif
13
14 #ifdef TEST_GMP
15 #include <boost/multiprecision/gmp.hpp>
16 #endif
17 #ifdef TEST_MPFR
18 #include <boost/multiprecision/mpfr.hpp>
19 #endif
20 #include <boost/multiprecision/cpp_dec_float.hpp>
21 #include "test.hpp"
22
23 template <class Number, class BigNumber>
24 void test()
25 {
26    using namespace boost::multiprecision;
27    typedef Number test_type;
28
29    test_type a = 1;
30    a /= 3;
31    test_type b = -a;
32
33    BigNumber r;
34    BOOST_CHECK_EQUAL(add(r, a, a), BigNumber(a) + BigNumber(a));
35    BOOST_CHECK_EQUAL(subtract(r, a, b), BigNumber(a) - BigNumber(b));
36    BOOST_CHECK_EQUAL(subtract(r, b, a), BigNumber(b) - BigNumber(a));
37    BOOST_CHECK_EQUAL(multiply(r, a, a), BigNumber(a) * BigNumber(a));
38 }
39
40 int main()
41 {
42    using namespace boost::multiprecision;
43
44    test<cpp_dec_float_50, cpp_dec_float_100>();
45
46 #ifdef TEST_GMP
47    test<mpf_float_50, mpf_float_100>();
48 #endif
49 #ifdef TEST_MPFR
50    test<mpfr_float_50, mpfr_float_100>();
51 #endif
52
53    return boost::report_errors();
54 }