]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_complex.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / serialization / test / test_complex.cpp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // test_complex.cpp
3
4 // (C) Copyright 2005 Matthias Troyer .
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 // should pass compilation and execution
10
11 #include <fstream>
12
13 #include <cstddef> // NULL
14 #include <cstdlib> // rand
15 #include <cstdio> // remove
16 #include <boost/config.hpp>
17 #include <boost/detail/workaround.hpp>
18 #include <boost/math/special_functions/next.hpp>
19
20 #if defined(BOOST_NO_STDC_NAMESPACE)
21 #include <boost/limits.hpp>
22 namespace std{
23 using ::rand;
24 using ::remove;
25 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(UNDER_CE)
26 using ::numeric_limits;
27 #endif
28 }
29 #endif
30
31 #include "test_tools.hpp"
32
33 #include <boost/preprocessor/stringize.hpp>
34 #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
35
36 #include <boost/serialization/complex.hpp>
37
38 #include <iostream>
39
40 int test_main( int /* argc */, char* /* argv */[] )
41 {
42 const char * testfile = boost::archive::tmpnam(NULL);
43 BOOST_REQUIRE(NULL != testfile);
44
45 // test array of objects
46 std::complex<float> a(
47 static_cast<float>(std::rand()) / static_cast<float>(std::rand()),
48 static_cast<float>(std::rand()) / static_cast<float>(std::rand())
49 );
50 std::complex<double> b(
51 static_cast<double>(std::rand()) / static_cast<double>(std::rand()),
52 static_cast<double>(std::rand()) / static_cast<double>(std::rand())
53 );
54 {
55 test_ostream os(testfile, TEST_STREAM_FLAGS);
56 test_oarchive oa(os);
57 oa << boost::serialization::make_nvp("afloatcomplex", a);
58 oa << boost::serialization::make_nvp("adoublecomplex", b);
59 }
60 std::complex<float> a1;
61 std::complex<double> b1;
62 {
63 test_istream is(testfile, TEST_STREAM_FLAGS);
64 test_iarchive ia(is);
65 ia >> boost::serialization::make_nvp("afloatcomplex", a1);
66 ia >> boost::serialization::make_nvp("adoublecomplex", b1);
67 }
68
69 std::cerr << "a.real()-a1a.real() distance = " << std::abs( boost::math::float_distance(a.real(), a1.real())) << std::endl;
70 BOOST_CHECK(std::abs(boost::math::float_distance(a.real(), a1.real())) < 2);
71 std::cerr << "a.imag() - a1a.imag() distance = " << std::abs( boost::math::float_distance(a.imag(), a1.imag())) << std::endl;
72 BOOST_CHECK(std::abs(boost::math::float_distance(a.imag(), a1.imag())) < 2);
73 std::cerr << "b.real() - b1.real() distance = " << std::abs( boost::math::float_distance(b.real(), b1.real())) << std::endl;
74 BOOST_CHECK(std::abs(boost::math::float_distance(b.real(), b1.real())) < 2);
75 std::cerr << "b.imag() - b1.imag() distance = " << std::abs( boost::math::float_distance(b.imag(), b1.imag())) << std::endl;
76 BOOST_CHECK(std::abs(boost::math::float_distance(b.imag(), b1.imag())) < 2);
77
78 std::remove(testfile);
79 return EXIT_SUCCESS;
80 }
81
82 // EOF