| 1 |
// 2006-01-12 Paolo Carlini <[email protected]> |
| 2 |
// |
| 3 |
// Copyright (C) 2006-2025 Free Software Foundation, Inc. |
| 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 |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 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 |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// 8.1 Additions to header <complex> |
| 21 |
|
| 22 |
#include <tr1/complex> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
#include <testsuite_tr1.h> |
| 25 |
|
| 26 |
void test01() |
| 27 |
{ |
| 28 |
using __gnu_test::check_ret_type; |
| 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; |
| 37 |
const double d1 = 1.0; |
| 38 |
|
| 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))) ); |
| 42 |
|
| 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))) ); |
| 46 |
|
| 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))) ); |
| 50 |
|
| 51 |
check_ret_type<double>(std::tr1::norm(i1)); |
| 52 |
VERIFY( std::tr1::norm(i1) == std::tr1::norm(double(i1)) ); |
| 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. |
| 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)); |
| 64 |
|
| 65 |
check_ret_type<cmplx_d_type>(std::tr1::pow(cmplx_f_type(f1, f1), i1)); |
| 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)); |
| 69 |
|
| 70 |
VERIFY( std::tr1::pow(cmplx_d_type(d1, d1), i1) |
| 71 |
== std::tr1::pow(cmplx_d_type(d1, d1), double(i1)) ); |
| 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)) ); |
| 76 |
|
| 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)) ); |
| 87 |
|
| 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))) ); |
| 91 |
} |
| 92 |
|
| 93 |
int main() |
| 94 |
{ |
| 95 |
test01(); |
| 96 |
return 0; |
| 97 |
} |