1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
///////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2002 - 2011.
// Copyright 2011 John Maddock. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
//
// This work is based on an earlier work:
// "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations",
// in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469
#ifdef _MSC_VER
#define _SCL_SECURE_NO_WARNINGS
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/array.hpp>
#include "test.hpp"
#include <boost/multiprecision/mpfr.hpp>
#include <boost/multiprecision/gmp.hpp>
int main()
{
using namespace boost::multiprecision;
//
// Test interconversions between GMP supported backends:
//
mpf_t mpf;
mpz_t mpz;
mpq_t mpq;
mpfr_t mpfr;
mpf_init2(mpf, 100);
mpf_set_ui(mpf, 2u);
mpz_init(mpz);
mpz_set_ui(mpz, 2u);
mpq_init(mpq);
mpq_set_ui(mpq, 2u, 1u);
mpfr_init(mpfr);
mpfr_set_ui(mpfr, 2u, GMP_RNDN);
BOOST_TEST(mpfr_float(mpf) == 2);
BOOST_TEST(mpfr_float_50(mpf) == 2);
BOOST_TEST(mpfr_float(mpz) == 2);
BOOST_TEST(mpfr_float_50(mpz) == 2);
BOOST_TEST(mpfr_float(mpq) == 2);
BOOST_TEST(mpfr_float_50(mpq) == 2);
BOOST_TEST(mpfr_float(mpfr) == 2);
BOOST_TEST(mpfr_float_50(mpfr) == 2);
mpfr_float f0;
mpfr_float_50 f50;
f0 = mpf;
BOOST_TEST(f0 == 2);
f0 = 0;
f0 = mpz;
BOOST_TEST(f0 == 2);
f0 = 0;
f0 = mpq;
BOOST_TEST(f0 == 2);
f0 = mpfr;
BOOST_TEST(f0 == 2);
f50 = mpf;
BOOST_TEST(f50 == 2);
f50 = 0;
f50 = mpz;
BOOST_TEST(f50 == 2);
f50 = 0;
f50 = mpq;
BOOST_TEST(f50 == 2);
f50 = mpfr;
BOOST_TEST(f50 == 2);
f50 = 4;
f0 = f50;
BOOST_TEST(f0 == 4);
f0 = 3;
f50 = f0;
BOOST_TEST(f50 == 3);
f50 = 4;
BOOST_TEST(mpfr_float(f50) == 4);
BOOST_TEST(mpfr_float_50(f0) == 3);
mpz_int iz(2);
mpq_rational rat(2);
mpf_float gf(2);
f50 = 3;
f50 = iz;
BOOST_TEST(f50 == 2);
f50 = 3;
f0 = iz;
BOOST_TEST(f0 == 2);
f50 = 3;
f0 = gf;
BOOST_TEST(f0 == 2);
BOOST_TEST(mpfr_float(iz) == 2);
BOOST_TEST(mpfr_float_50(iz) == 2);
BOOST_TEST(mpfr_float(rat) == 2);
BOOST_TEST(mpfr_float_50(rat) == 2);
BOOST_TEST(mpfr_float(gf) == 2);
BOOST_TEST(mpfr_float_50(gf) == 2);
//
// Conversions involving precision only:
//
mpfr_float::default_precision(30);
f50 = 2;
mpfr_float_100 f100(3);
mpfr_float f0a(4);
mpfr_float f0b(f100);
BOOST_TEST(f0a.precision() == 30);
BOOST_TEST(f0b.precision() == 100);
f0a = f100;
BOOST_TEST(f0a == 3);
BOOST_TEST(f0a.precision() == 100); // precision preserved on assignment
f100 = f50;
BOOST_TEST(f100 == 2);
f50 = static_cast<mpfr_float_50>(f100);
mpf_clear(mpf);
mpz_clear(mpz);
mpq_clear(mpq);
mpfr_clear(mpfr);
return boost::report_errors();
}
|