]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/tr1/8_c_compatibility/complex/overloads_int.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 8_c_compatibility / complex / overloads_int.cc
CommitLineData
90922b2d
PC
1// 2006-01-12 Paolo Carlini <pcarlini@suse.de>
2//
a5544970 3// Copyright (C) 2006-2019 Free Software Foundation, Inc.
90922b2d
PC
4//
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
90922b2d
PC
9// any later version.
10//
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.
15//
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
90922b2d
PC
19
20// 8.1 Additions to header <complex>
21
22#include <tr1/complex>
23#include <testsuite_hooks.h>
24#include <testsuite_tr1.h>
25
26void test01()
27{
9a7ab578 28 using __gnu_test::check_ret_type;
90922b2d
PC
29
30 typedef std::complex<float> cmplx_f_type;
31 typedef std::complex<double> cmplx_d_type;
32
33 const int i1 = 1;
34 const unsigned u1 = 1;
35 const long l1 = 1;
36 const double f1 = 1.0f;
90922b2d 37 const double d1 = 1.0;
f92ab29f 38
9a7ab578
PC
39 check_ret_type<double>(std::tr1::arg(i1));
40 VERIFY( std::tr1::arg(i1) == std::tr1::arg(double(i1)) );
41 VERIFY( std::tr1::arg(i1) == std::tr1::arg(cmplx_d_type(double(i1))) );
90922b2d 42
9a7ab578
PC
43 check_ret_type<cmplx_d_type>(std::tr1::conj(i1));
44 VERIFY( std::tr1::conj(i1) == std::tr1::conj(double(i1)) );
45 VERIFY( std::tr1::conj(i1) == std::tr1::conj(cmplx_d_type(double(i1))) );
90922b2d 46
9a7ab578
PC
47 check_ret_type<double>(std::tr1::imag(i1));
48 VERIFY( std::tr1::imag(i1) == std::tr1::imag(double(i1)) );
49 VERIFY( std::tr1::imag(i1) == std::tr1::imag(cmplx_d_type(double(i1))) );
90922b2d 50
9a7ab578
PC
51 check_ret_type<double>(std::tr1::norm(i1));
52 VERIFY( std::tr1::norm(i1) == std::tr1::norm(double(i1)) );
fd22159f
PC
53 // std::norm<const complex<>&) is mathematically equivalent to just
54 // this for a real, but the general algorithm goes through std::abs
55 // and a multiplication.
9a7ab578
PC
56 VERIFY( std::tr1::norm(i1) == double(i1) * double(i1) );
57
58 // NB: The existing std::polar wins and a cmplx_i_type is returned.
59 // check_ret_type<cmplx_d_type>(std::tr1::polar(i1, i1));
60 // VERIFY( std::tr1::polar(i1, i1)
61 // == std::tr1::polar(double(i1), double(i1)) );
62 typedef std::complex<int> cmplx_i_type;
63 check_ret_type<cmplx_i_type>(std::tr1::polar(i1, i1));
90922b2d 64
3fd29fa9 65 check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_f_type(f1, f1), i1));
9a7ab578
PC
66 check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_f_type(f1, f1), u1));
67 check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_f_type(f1, f1), l1));
68 check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_d_type(d1, d1), i1));
2482200f 69
3fd29fa9
PC
70 VERIFY( std::tr1::pow(cmplx_d_type(d1, d1), i1)
71 == std::tr1::pow(cmplx_d_type(d1, d1), double(i1)) );
9a7ab578
PC
72 VERIFY( std::tr1::pow(cmplx_d_type(d1, d1), u1)
73 == std::tr1::pow(cmplx_d_type(d1, d1), double(u1)) );
74 VERIFY( std::tr1::pow(cmplx_d_type(d1, d1), l1)
75 == std::tr1::pow(cmplx_d_type(d1, d1), double(l1)) );
90922b2d 76
9a7ab578
PC
77 check_ret_type<cmplx_d_type>(std::tr1::pow(i1, cmplx_f_type(f1, f1)));
78 check_ret_type<cmplx_d_type>(std::tr1::pow(u1, cmplx_f_type(f1, f1)));
79 check_ret_type<cmplx_d_type>(std::tr1::pow(l1, cmplx_f_type(f1, f1)));
80 check_ret_type<cmplx_d_type>(std::tr1::pow(i1, cmplx_d_type(d1, d1)));
81 VERIFY( std::tr1::pow(i1, cmplx_d_type(d1, d1))
82 == std::tr1::pow(double(i1), cmplx_d_type(d1, d1)) );
83 VERIFY( std::tr1::pow(u1, cmplx_d_type(d1, d1))
84 == std::tr1::pow(double(u1), cmplx_d_type(d1, d1)) );
85 VERIFY( std::tr1::pow(l1, cmplx_d_type(d1, d1))
86 == std::tr1::pow(double(l1), cmplx_d_type(d1, d1)) );
90922b2d 87
9a7ab578
PC
88 check_ret_type<double>(std::tr1::real(i1));
89 VERIFY( std::tr1::real(i1) == std::tr1::real(double(i1)) );
90 VERIFY( std::tr1::real(i1) == std::tr1::real(cmplx_d_type(double(i1))) );
90922b2d
PC
91}
92
93int main()
94{
95 test01();
96 return 0;
97}