]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/8_c_compatibility/complex/overloads_int.cc
1 // 2006-01-12 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2006-2013 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 8.1 Additions to header <complex>
22 #include <tr1/complex>
23 #include <testsuite_hooks.h>
24 #include <testsuite_tr1.h>
28 bool test
__attribute__((unused
)) = true;
29 using __gnu_test::check_ret_type
;
31 typedef std::complex<float> cmplx_f_type
;
32 typedef std::complex<double> cmplx_d_type
;
35 const unsigned u1
= 1;
37 const double f1
= 1.0f
;
38 const double d1
= 1.0;
40 check_ret_type
<double>(std::tr1::arg(i1
));
41 VERIFY( std::tr1::arg(i1
) == std::tr1::arg(double(i1
)) );
42 VERIFY( std::tr1::arg(i1
) == std::tr1::arg(cmplx_d_type(double(i1
))) );
44 check_ret_type
<cmplx_d_type
>(std::tr1::conj(i1
));
45 VERIFY( std::tr1::conj(i1
) == std::tr1::conj(double(i1
)) );
46 VERIFY( std::tr1::conj(i1
) == std::tr1::conj(cmplx_d_type(double(i1
))) );
48 check_ret_type
<double>(std::tr1::imag(i1
));
49 VERIFY( std::tr1::imag(i1
) == std::tr1::imag(double(i1
)) );
50 VERIFY( std::tr1::imag(i1
) == std::tr1::imag(cmplx_d_type(double(i1
))) );
52 check_ret_type
<double>(std::tr1::norm(i1
));
53 VERIFY( std::tr1::norm(i1
) == std::tr1::norm(double(i1
)) );
54 // std::norm<const complex<>&) is mathematically equivalent to just
55 // this for a real, but the general algorithm goes through std::abs
56 // and a multiplication.
57 VERIFY( std::tr1::norm(i1
) == double(i1
) * double(i1
) );
59 // NB: The existing std::polar wins and a cmplx_i_type is returned.
60 // check_ret_type<cmplx_d_type>(std::tr1::polar(i1, i1));
61 // VERIFY( std::tr1::polar(i1, i1)
62 // == std::tr1::polar(double(i1), double(i1)) );
63 typedef std::complex<int> cmplx_i_type
;
64 check_ret_type
<cmplx_i_type
>(std::tr1::polar(i1
, i1
));
66 check_ret_type
<cmplx_d_type
>(std::tr1::pow(cmplx_f_type(f1
, f1
), i1
));
67 check_ret_type
<cmplx_d_type
>(std::tr1::pow(cmplx_f_type(f1
, f1
), u1
));
68 check_ret_type
<cmplx_d_type
>(std::tr1::pow(cmplx_f_type(f1
, f1
), l1
));
69 check_ret_type
<cmplx_d_type
>(std::tr1::pow(cmplx_d_type(d1
, d1
), i1
));
71 VERIFY( std::tr1::pow(cmplx_d_type(d1
, d1
), i1
)
72 == std::tr1::pow(cmplx_d_type(d1
, d1
), double(i1
)) );
73 VERIFY( std::tr1::pow(cmplx_d_type(d1
, d1
), u1
)
74 == std::tr1::pow(cmplx_d_type(d1
, d1
), double(u1
)) );
75 VERIFY( std::tr1::pow(cmplx_d_type(d1
, d1
), l1
)
76 == std::tr1::pow(cmplx_d_type(d1
, d1
), double(l1
)) );
78 check_ret_type
<cmplx_d_type
>(std::tr1::pow(i1
, cmplx_f_type(f1
, f1
)));
79 check_ret_type
<cmplx_d_type
>(std::tr1::pow(u1
, cmplx_f_type(f1
, f1
)));
80 check_ret_type
<cmplx_d_type
>(std::tr1::pow(l1
, cmplx_f_type(f1
, f1
)));
81 check_ret_type
<cmplx_d_type
>(std::tr1::pow(i1
, cmplx_d_type(d1
, d1
)));
82 VERIFY( std::tr1::pow(i1
, cmplx_d_type(d1
, d1
))
83 == std::tr1::pow(double(i1
), cmplx_d_type(d1
, d1
)) );
84 VERIFY( std::tr1::pow(u1
, cmplx_d_type(d1
, d1
))
85 == std::tr1::pow(double(u1
), cmplx_d_type(d1
, d1
)) );
86 VERIFY( std::tr1::pow(l1
, cmplx_d_type(d1
, d1
))
87 == std::tr1::pow(double(l1
), cmplx_d_type(d1
, d1
)) );
89 check_ret_type
<double>(std::tr1::real(i1
));
90 VERIFY( std::tr1::real(i1
) == std::tr1::real(double(i1
)) );
91 VERIFY( std::tr1::real(i1
) == std::tr1::real(cmplx_d_type(double(i1
))) );