]> www.ginac.de Git - ginac.git/blob - check/numeric_archive.cpp
Finalize 1.7.5 release.
[ginac.git] / check / numeric_archive.cpp
1 /** @file numeric_archive.cpp
2  *
3  *  Check for a bug in numeric::archive
4  *
5  *  numeric::archive used to fail if the real part of a complex number
6  *  is a rational number and the imaginary part is a floating point one. */
7
8 /*
9  *  GiNaC Copyright (C) 1999-2019 Johannes Gutenberg University Mainz, Germany
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24  */
25
26 #include "ginac.h"
27 using namespace GiNaC;
28
29 #include <algorithm>
30 #include <cln/cln.h>
31 #include <iostream>
32 #include <iterator>
33 #include <sstream>
34 #include <stdexcept>
35 #include <vector>
36 using namespace cln;
37
38 struct archive_unarchive_check
39 {
40         cl_N operator()(const cl_N& n) const
41         {
42                 ex e = numeric(n);
43                 archive ar;
44                 ar.archive_ex(e, "test");
45                 lst l;
46                 ex check = ar.unarchive_ex(l, "test");
47                 if (!check.is_equal(e)) {
48                         std::ostringstream s;
49                         s << __FILE__ << ':' << __LINE__ << ": expected: " << e << ", got " << check;
50                         throw std::logic_error(s.str());
51                 }
52                 return n;
53         }
54 };
55
56 int main(int argc, char** argv)
57 {
58         const cl_I one(1);
59         std::cout << "checking if numeric::archive handles complex numbers properly" << std::endl;
60         const cl_R three_fp = cl_float(3.0, default_float_format);
61         std::vector<cl_N> numbers;
62         numbers.push_back(complex(one, three_fp));
63         numbers.push_back(complex(three_fp, one));
64         numbers.push_back(complex(three_fp, three_fp));
65         numbers.push_back(complex(one, one));
66         std::for_each(numbers.begin(), numbers.end(), archive_unarchive_check());
67         return 0;
68 }