1 /** @file numeric_archive.cpp
3 * Check for a bug in numeric::archive
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. */
9 * GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
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.
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.
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
27 using namespace GiNaC;
38 struct archive_unarchive_check
40 cl_N operator()(const cl_N& n) const
44 ar.archive_ex(e, "test");
46 ex check = ar.unarchive_ex(l, "test");
47 if (!check.is_equal(e)) {
49 s << __FILE__ << ':' << __LINE__ << ": expected: " << e << ", got " << check;
50 throw std::logic_error(s.str());
56 int main(int argc, char** argv)
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());