1 // 2006-01-12 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2006 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // 8.1 Additions to header <complex>
23 #include <tr1/complex>
24 #include <testsuite_hooks.h>
25 #include <testsuite_tr1.h>
29 bool test __attribute__((unused)) = true;
30 using __gnu_test::check_ret_type;
32 typedef std::complex<float> cmplx_f_type;
33 typedef std::complex<double> cmplx_d_type;
36 const unsigned u1 = 1;
38 const double f1 = 1.0f;
39 const double d1 = 1.0;
41 check_ret_type<double>(std::tr1::arg(i1));
42 VERIFY( std::tr1::arg(i1) == std::tr1::arg(double(i1)) );
43 VERIFY( std::tr1::arg(i1) == std::tr1::arg(cmplx_d_type(double(i1))) );
45 check_ret_type<cmplx_d_type>(std::tr1::conj(i1));
46 VERIFY( std::tr1::conj(i1) == std::tr1::conj(double(i1)) );
47 VERIFY( std::tr1::conj(i1) == std::tr1::conj(cmplx_d_type(double(i1))) );
49 check_ret_type<double>(std::tr1::imag(i1));
50 VERIFY( std::tr1::imag(i1) == std::tr1::imag(double(i1)) );
51 VERIFY( std::tr1::imag(i1) == std::tr1::imag(cmplx_d_type(double(i1))) );
53 check_ret_type<double>(std::tr1::norm(i1));
54 VERIFY( std::tr1::norm(i1) == std::tr1::norm(double(i1)) );
55 // std::norm<const complex<>&) is mathematically equivalent to just
56 // this for a real, but the general algorithm goes through std::abs
57 // and a multiplication.
58 VERIFY( std::tr1::norm(i1) == double(i1) * double(i1) );
60 // NB: The existing std::polar wins and a cmplx_i_type is returned.
61 // check_ret_type<cmplx_d_type>(std::tr1::polar(i1, i1));
62 // VERIFY( std::tr1::polar(i1, i1)
63 // == std::tr1::polar(double(i1), double(i1)) );
64 typedef std::complex<int> cmplx_i_type;
65 check_ret_type<cmplx_i_type>(std::tr1::polar(i1, i1));
67 // NB: According to the letter of 8.1.9/3 the return type should be a
68 // cmplx_d_type, but the existing std::pow(const complex<>&, int) wins.
69 // check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_f_type(f1, f1), i1));
70 check_ret_type<cmplx_f_type>(std::tr1::pow(cmplx_f_type(f1, f1), i1));
72 check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_f_type(f1, f1), u1));
73 check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_f_type(f1, f1), l1));
74 check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_d_type(d1, d1), i1));
77 // VERIFY( std::tr1::pow(cmplx_d_type(d1, d1), i1)
78 // == std::tr1::pow(cmplx_d_type(d1, d1), double(i1)) );
79 VERIFY( std::tr1::pow(cmplx_d_type(d1, d1), u1)
80 == std::tr1::pow(cmplx_d_type(d1, d1), double(u1)) );
81 VERIFY( std::tr1::pow(cmplx_d_type(d1, d1), l1)
82 == std::tr1::pow(cmplx_d_type(d1, d1), double(l1)) );
84 check_ret_type<cmplx_d_type>(std::tr1::pow(i1, cmplx_f_type(f1, f1)));
85 check_ret_type<cmplx_d_type>(std::tr1::pow(u1, cmplx_f_type(f1, f1)));
86 check_ret_type<cmplx_d_type>(std::tr1::pow(l1, cmplx_f_type(f1, f1)));
87 check_ret_type<cmplx_d_type>(std::tr1::pow(i1, cmplx_d_type(d1, d1)));
88 VERIFY( std::tr1::pow(i1, cmplx_d_type(d1, d1))
89 == std::tr1::pow(double(i1), cmplx_d_type(d1, d1)) );
90 VERIFY( std::tr1::pow(u1, cmplx_d_type(d1, d1))
91 == std::tr1::pow(double(u1), cmplx_d_type(d1, d1)) );
92 VERIFY( std::tr1::pow(l1, cmplx_d_type(d1, d1))
93 == std::tr1::pow(double(l1), cmplx_d_type(d1, d1)) );
95 check_ret_type<double>(std::tr1::real(i1));
96 VERIFY( std::tr1::real(i1) == std::tr1::real(double(i1)) );
97 VERIFY( std::tr1::real(i1) == std::tr1::real(cmplx_d_type(double(i1))) );