diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/26_numerics/complex | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/26_numerics/complex')
18 files changed, 1096 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/26_numerics/complex/13450.cc b/libstdc++-v3/testsuite/26_numerics/complex/13450.cc new file mode 100644 index 000000000..c34648e20 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/13450.cc @@ -0,0 +1,82 @@ +// { dg-do run { xfail broken_cplxf_arg } } + +// Copyright (C) 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 26.2.8 complex transcendentals + +#include <complex> +#include <limits> +#include <testsuite_hooks.h> + +template<typename T> + void test01_do(T a, T b) + { + using namespace std; + bool test __attribute__((unused)) = true; + typedef complex<T> cplx; + + T eps = numeric_limits<T>::epsilon() * 100; + + cplx ref = pow(cplx(a, T()), cplx(b, T())); + cplx res1 = pow(a, cplx(b, T())); + cplx res2 = pow(cplx(a, T()), b); + + VERIFY( abs(ref - res1) < eps ); + VERIFY( abs(ref - res2) < eps ); + VERIFY( abs(res1 - res2) < eps ); + } + +// libstdc++/13450 +void test01() +{ + float f1 = -1.0f; + float f2 = 0.5f; + test01_do(f1, f2); + + f1 = -3.2f; + f2 = 1.4f; + test01_do(f1, f2); + + double d1 = -1.0; + double d2 = 0.5; + test01_do(d1, d2); + + d1 = -3.2; + d2 = 1.4; + test01_do(d1, d2); + +#if __LDBL_MANT_DIG__ != 106 + /* For IBM long double, epsilon is too small (since 1.0 plus any + double is representable) to be able to expect results within + epsilon * 100 (which may be much less than 1ulp for a particular + long double value). */ + long double ld1 = -1.0l; + long double ld2 = 0.5l; + test01_do(ld1, ld2); + + ld1 = -3.2l; + ld2 = 1.4l; + test01_do(ld1, ld2); +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/50880.cc b/libstdc++-v3/testsuite/26_numerics/complex/50880.cc new file mode 100644 index 000000000..2b70a99dd --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/50880.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=gnu++0x" } +// +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_hooks.h> + +template<typename T> + void test01_do() + { + bool test __attribute__((unused)) = true; + + const std::complex<T> ca(T(-2), T(2)); + const std::complex<T> cb(T(-2), T(0)); + const std::complex<T> cc(T(-2), T(-2)); + + std::complex<T> cra = std::acosh(ca); + std::complex<T> crb = std::acosh(cb); + std::complex<T> crc = std::acosh(cc); + + VERIFY( cra.real() > T(0) ); + VERIFY( crb.real() > T(0) ); + VERIFY( crc.real() > T(0) ); + } + +// libstdc++/50880 +void test01() +{ + test01_do<float>(); + test01_do<double>(); + test01_do<long double>(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/51083.cc b/libstdc++-v3/testsuite/26_numerics/complex/51083.cc new file mode 100644 index 000000000..54e781ba1 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/51083.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++0x" } +// +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> + +namespace a +{ + template<typename> class Mat { }; + + template<typename T> struct Mat2 : Mat<T> { }; + + template<typename T> int arg(Mat<T>) { return 1; } + template<typename T> int conj(Mat<T>) { return 1; } + template<typename T> int imag(Mat<T>) { return 1; } + template<typename T> int norm(Mat<T>) { return 1; } + template<typename T> int proj(Mat<T>) { return 1; } + template<typename T> int real(Mat<T>) { return 1; } + + template<typename T, typename U> int pow(Mat<T>, U) { return 1; } + template<typename T, typename U> int pow(T, Mat<U>) { return 1; } +} + +int main() +{ + int __attribute__((unused)) i; + + using namespace std; + + a::Mat2< std::complex<double> > c; + i = arg(c); + i = conj(c); + i = imag(c); + i = norm(c); + i = proj(c); + i = real(c); + i = pow(std::complex<float>(), c); + i = pow(c, std::complex<float>()); +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/buggy_complex.cc b/libstdc++-v3/testsuite/26_numerics/complex/buggy_complex.cc new file mode 100644 index 000000000..a6cbc9991 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/buggy_complex.cc @@ -0,0 +1,35 @@ +// 2000-02-09 +// Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr> + +// Copyright (C) 1999, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Test buggy builtin GNU __complex__ support. This used to cause +// an ICE on some 64-bits plateforms. +// Origin: petter@matfys.lth.se + +#include <complex> + +int main() +{ + std::complex<double> a(9), b(0, 8), c; + + c = a * b; + + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/comparison_operators/constexpr.cc b/libstdc++-v3/testsuite/26_numerics/complex/comparison_operators/constexpr.cc new file mode 100644 index 000000000..85c3ab7b4 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/comparison_operators/constexpr.cc @@ -0,0 +1,39 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_comparison_eq_ne test; + test.operator()<std::complex<float>>(); + test.operator()<std::complex<float>, float>(); + test.operator()<float,std::complex<float>>(); + + test.operator()<std::complex<double>>(); + test.operator()<std::complex<double>, double>(); + test.operator()<double,std::complex<double>>(); + + test.operator()<std::complex<long double>>(); + test.operator()<std::complex<long double>, long double>(); + test.operator()<long double,std::complex<long double>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/cons/48760.cc b/libstdc++-v3/testsuite/26_numerics/complex/cons/48760.cc new file mode 100644 index 000000000..0027a34e4 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/cons/48760.cc @@ -0,0 +1,58 @@ +// { dg-require-c-std "" } + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <limits> +#include <testsuite_hooks.h> + +template<typename T> + void do_test01() + { + bool test __attribute__((unused)) = true; + + if (std::numeric_limits<T>::has_quiet_NaN) + { + std::complex<T> c1(T(0), std::numeric_limits<T>::quiet_NaN()); + VERIFY( c1.real() == T(0) ); + VERIFY( std::isnan(c1.imag()) ); + + std::complex<T> c2(std::numeric_limits<T>::quiet_NaN(), T(0)); + VERIFY( std::isnan(c2.real()) ); + VERIFY( c2.imag() == T(0) ); + + std::complex<T> c3(std::numeric_limits<T>::quiet_NaN(), + std::numeric_limits<T>::quiet_NaN()); + VERIFY( std::isnan(c3.real()) ); + VERIFY( std::isnan(c3.imag()) ); + } + } + +// libstdc++/48760 +void test01() +{ + do_test01<float>(); + do_test01<double>(); + do_test01<long double>(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/cons/constexpr.cc b/libstdc++-v3/testsuite/26_numerics/complex/cons/constexpr.cc new file mode 100644 index 000000000..13d3c8168 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/cons/constexpr.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_default_constructible test1; + test1.operator()<std::complex<float>>(); + test1.operator()<std::complex<double>>(); + test1.operator()<std::complex<long double>>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator()<std::complex<float>, float>(); + test2.operator()<std::complex<double>, double>(); + test2.operator()<std::complex<long double>, long double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/cons/constexpr_primary.cc b/libstdc++-v3/testsuite/26_numerics/complex/cons/constexpr_primary.cc new file mode 100644 index 000000000..77e01bcff --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/cons/constexpr_primary.cc @@ -0,0 +1,67 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> + +// User defined type, so that the primary std::complex template is used. +namespace numext +{ + struct ldld_base + { + long double one; + long double two; + }; + + struct ldld_lit : public ldld_base + { }; + + struct ldld_nonlit : public ldld_base + { + ~ldld_nonlit() { } + }; + + bool + operator<(const ldld_base __a, const ldld_base __b) + { return __a.one < __b.one && __a.two < __b.two; } + + bool + operator==(const ldld_base __a, const ldld_base __b) + { return __a.one == __b.one && __a.two == __b.two; } + + ldld_base + operator+=(const ldld_base __a, const ldld_base __b) + { return ldld_base({ __a.one + __b.one, __a.two + __b.two}); } + + ldld_base + operator-=(const ldld_base __a, const ldld_base __b) + { return ldld_base({ __a.one - __b.one, __a.two - __b.two}); } + + ldld_base + operator*=(const ldld_base __a, const ldld_base __b) + { return ldld_base({ __a.one * __b.one, __a.two * __b.two}); } + + ldld_base + operator/=(const ldld_base __a, const ldld_base __b) + { return ldld_base({ __a.one / __b.one, __a.two / __b.two}); } + +} + +constexpr std::complex<numext::ldld_lit> lit; // ok +// constexpr std::complex<numext::ldld_nonlit> nonlit; // error diff --git a/libstdc++-v3/testsuite/26_numerics/complex/dr387_2.cc b/libstdc++-v3/testsuite/26_numerics/complex/dr387_2.cc new file mode 100644 index 000000000..06e0380cc --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/dr387_2.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// +// Copyright (C) 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> + +// DR 387. std::complex over-encapsulated. +// http://gcc.gnu.org/ml/gcc/2009-03/msg00264.html +typedef std::complex<double> C; + +C f1(C& c) { return c+1.0; } +C f2(C& c) { return c-1.0; } +C f3(C& c) { return 1.0+c; } +C f4(C& c) { return 1.0-c; } diff --git a/libstdc++-v3/testsuite/26_numerics/complex/dr781_dr1137.cc b/libstdc++-v3/testsuite/26_numerics/complex/dr781_dr1137.cc new file mode 100644 index 000000000..145a4b044 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/dr781_dr1137.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++0x" } +// 2008-05-22 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +// DR 781. std::complex should add missing C99 functions. +// DR 1137. Return type of conj and proj. +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::check_ret_type; + + typedef std::complex<float> cmplx_f_type; + typedef std::complex<double> cmplx_d_type; + typedef std::complex<long double> cmplx_ld_type; + + const int i1 = 1; + const float f1 = 1.0f; + const double d1 = 1.0; + const long double ld1 = 1.0l; + + const cmplx_f_type c_f1(f1, f1); + const cmplx_d_type c_d1(d1, d1); + const cmplx_ld_type c_ld1(ld1, ld1); + + check_ret_type<cmplx_f_type>(std::proj(c_f1)); + check_ret_type<cmplx_d_type>(std::proj(c_d1)); + check_ret_type<cmplx_ld_type>(std::proj(c_ld1)); + + check_ret_type<float>(std::proj(f1)); + check_ret_type<double>(std::proj(d1)); + check_ret_type<double>(std::proj(i1)); + VERIFY( std::proj(i1) == std::proj(double(i1)) ); + check_ret_type<long double>(std::proj(ld1)); + + check_ret_type<cmplx_f_type>(std::conj(c_f1)); + check_ret_type<cmplx_d_type>(std::conj(c_d1)); + check_ret_type<cmplx_ld_type>(std::conj(c_ld1)); + + check_ret_type<float>(std::conj(f1)); + check_ret_type<double>(std::conj(d1)); + check_ret_type<double>(std::conj(i1)); + VERIFY( std::conj(i1) == std::conj(double(i1)) ); + check_ret_type<long double>(std::conj(ld1)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/dr844.cc b/libstdc++-v3/testsuite/26_numerics/complex/dr844.cc new file mode 100644 index 000000000..909ec27a9 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/dr844.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-12 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +// DR 844. complex pow return type is ambiguous. +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::check_ret_type; + + typedef std::complex<float> cmplx_f_type; + typedef std::complex<double> cmplx_d_type; + typedef std::complex<long double> cmplx_ld_type; + + const int i1 = 1; + const float f1 = 1.0f; + const double d1 = 1.0; + const long double ld1 = 1.0l; + + check_ret_type<cmplx_d_type>(std::pow(cmplx_f_type(f1, f1), i1)); + VERIFY( std::pow(cmplx_f_type(f1, f1), i1) + == std::pow(cmplx_d_type(f1, f1), double(i1)) ); + check_ret_type<cmplx_d_type>(std::pow(cmplx_d_type(d1, d1), i1)); + check_ret_type<cmplx_ld_type>(std::pow(cmplx_ld_type(ld1, ld1), i1)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/1.cc b/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/1.cc new file mode 100644 index 000000000..b7e65594c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/1.cc @@ -0,0 +1,138 @@ +// 2000-02-10 +// Petter Urkedal <petter@matfys.lth.se> + +// Copyright (C) 2000, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <iostream> +#include <string> +#include <sstream> +#include <complex> +#include <testsuite_hooks.h> +#include <cmath> + +template<typename R> +inline bool flteq(R x, R y) +{ + if (x == R(0)) return y == R(0); + else return std::fabs(x-y) < 1e-6*std::fabs(x); +} + +template<typename R> +int +test_good(std::string str, R x, R y) +{ + bool test __attribute__((unused)) = true; + std::complex<R> z; + char ch; + std::istringstream iss(str); + iss >> z >> ch; + VERIFY( iss.good() ); + VERIFY( flteq(z.real(), x) ); + VERIFY( flteq(z.imag(), y) ); + VERIFY( ch == '#' ); + return 0; +} + +template<typename R> +int +test_fail(std::string str) +{ + bool test __attribute__((unused)) = true; + std::complex<R> z; + std::istringstream iss(str); + iss >> z; + VERIFY( iss.fail() && !iss.bad() ); + return 0; +} + +template<typename R> +int +testall() +{ + test_good<R>("(-1.1,3.7)#", -1.1, 3.7); + test_good<R>("( .7e6 , \n-3.1)#", .7e6, -3.1); + test_good<R>("(\t0,-1)#", 0.0, -1.0); + test_good<R>("(-3.14)#", -3.14, 0.0); + test_good<R>("-.1#", -.1, 0.0); + test_good<R>(" ( -2.7e3 )#", -2.7e3, 0.0); + test_good<R>(" -.1#", -.1, 0.0); + test_fail<R>("(a,1)"); + test_fail<R>("(,1)"); + test_fail<R>("(1,a)"); + test_fail<R>("(1, )"); + test_fail<R>("|1,1)"); + test_fail<R>("(1|1)"); + test_fail<R>("(1,1|"); + return 0; +} + +// libstdc++/2970 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + complex<float> cf01(-1.1, -333.2); + stringstream ss; + ss << cf01; + string str = ss.str(); + VERIFY( str == "(-1.1,-333.2)" ); +} + +// libstdc++/2985 +struct gnu_char_traits : public std::char_traits<char> +{ }; + +typedef std::basic_ostringstream<char, gnu_char_traits> gnu_sstream; +template class std::basic_string<char, gnu_char_traits, std::allocator<char> >; + +void test02() +{ + bool test __attribute__((unused)) = true; + + // Construct locale with specialized facets. + typedef gnu_sstream::__num_put_type numput_type; + typedef gnu_sstream::__num_get_type numget_type; + std::locale loc_c = std::locale::classic(); + std::locale loc_1(loc_c, new numput_type); + std::locale loc_2(loc_1, new numget_type); + VERIFY( std::has_facet<numput_type>(loc_2) ); + VERIFY( std::has_facet<numget_type>(loc_2) ); + + gnu_sstream sstr; + sstr.imbue(loc_2); + + + std::complex<double> x(3, 4); + sstr << x; + VERIFY( sstr.str() == "(3,4)" ); +} + +int +main() +{ + testall<float>(); + testall<double>(); + testall<long double>(); + + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/wchar_t/1.cc b/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/wchar_t/1.cc new file mode 100644 index 000000000..8b23aec19 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/wchar_t/1.cc @@ -0,0 +1,136 @@ +// Copyright (C) 2007, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <iostream> +#include <string> +#include <sstream> +#include <complex> +#include <testsuite_hooks.h> +#include <cmath> + +template<typename R> +inline bool flteq(R x, R y) +{ + if (x == R(0)) return y == R(0); + else return std::fabs(x-y) < 1e-6*std::fabs(x); +} + +template<typename R> +int +test_good(std::wstring str, R x, R y) +{ + bool test __attribute__((unused)) = true; + std::complex<R> z; + wchar_t ch; + std::wistringstream iss(str); + iss >> z >> ch; + VERIFY( iss.good() ); + VERIFY( flteq(z.real(), x) ); + VERIFY( flteq(z.imag(), y) ); + VERIFY( ch == L'#' ); + return 0; +} + +template<typename R> +int +test_fail(std::wstring str) +{ + bool test __attribute__((unused)) = true; + std::complex<R> z; + std::wistringstream iss(str); + iss >> z; + VERIFY( iss.fail() && !iss.bad() ); + return 0; +} + +template<typename R> +int +testall() +{ + test_good<R>(L"(-1.1,3.7)#", -1.1, 3.7); + test_good<R>(L"( .7e6 , \n-3.1)#", .7e6, -3.1); + test_good<R>(L"(\t0,-1)#", 0.0, -1.0); + test_good<R>(L"(-3.14)#", -3.14, 0.0); + test_good<R>(L"-.1#", -.1, 0.0); + test_good<R>(L" ( -2.7e3 )#", -2.7e3, 0.0); + test_good<R>(L" -.1#", -.1, 0.0); + test_fail<R>(L"(a,1)"); + test_fail<R>(L"(,1)"); + test_fail<R>(L"(1,a)"); + test_fail<R>(L"(1, )"); + test_fail<R>(L"|1,1)"); + test_fail<R>(L"(1|1)"); + test_fail<R>(L"(1,1|"); + return 0; +} + +// libstdc++/2970 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + complex<float> cf01(-1.1, -333.2); + wstringstream ss; + ss << cf01; + wstring str = ss.str(); + VERIFY( str == L"(-1.1,-333.2)" ); +} + +// libstdc++/2985 +struct gnu_char_traits : public std::char_traits<wchar_t> +{ }; + +typedef std::basic_ostringstream<wchar_t, gnu_char_traits> gnu_sstream; +template class std::basic_string<wchar_t, gnu_char_traits, + std::allocator<wchar_t> >; + +void test02() +{ + bool test __attribute__((unused)) = true; + + // Construct locale with specialized facets. + typedef gnu_sstream::__num_put_type numput_type; + typedef gnu_sstream::__num_get_type numget_type; + std::locale loc_c = std::locale::classic(); + std::locale loc_1(loc_c, new numput_type); + std::locale loc_2(loc_1, new numget_type); + VERIFY( std::has_facet<numput_type>(loc_2) ); + VERIFY( std::has_facet<numget_type>(loc_2) ); + + gnu_sstream sstr; + sstr.imbue(loc_2); + + + std::complex<double> x(3, 4); + sstr << x; + VERIFY( sstr.str() == L"(3,4)" ); +} + +int +main() +{ + testall<float>(); + testall<double>(); + testall<long double>(); + + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/pow.cc b/libstdc++-v3/testsuite/26_numerics/complex/pow.cc new file mode 100644 index 000000000..a43e3c674 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/pow.cc @@ -0,0 +1,16 @@ +// { dg-do run { xfail broken_cplxf_arg } } +// PR libstdc++/10689 +// Origin: Daniel.Levine@jhuaph.edu +// { dg-add-options ieee } + +#include <complex> +#include <testsuite_hooks.h> + +int main() +{ + std::complex<double> z; + + VERIFY( pow(z, 1.0/3.0) == 0.0 ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/26_numerics/complex/requirements/constexpr_functions.cc new file mode 100644 index 000000000..eae5ee7e8 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/requirements/constexpr_functions.cc @@ -0,0 +1,57 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_member_functions + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + typedef typename _Ttesttype::_ComplexT _ComplexT; + const _ComplexT cc = { 1.1 }; + constexpr _Ttesttype a(cc); + constexpr auto v1 __attribute__((unused)) = a.real(); + constexpr auto v2 __attribute__((unused)) = a.imag(); + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_member_functions test; + test.operator()<std::complex<float>>(); + test.operator()<std::complex<double>>(); + test.operator()<std::complex<long double>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/value_operations/1.cc b/libstdc++-v3/testsuite/26_numerics/complex/value_operations/1.cc new file mode 100644 index 000000000..dc05a2b19 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/value_operations/1.cc @@ -0,0 +1,65 @@ +// { dg-do run { xfail broken_cplxf_arg } } +// { dg-options "-O0" } +// 2000-11-20 +// Benjamin Kosnik bkoz@redhat.com + +// Copyright (C) 2000, 2003, 2004, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + typedef complex<double> complex_type; + const double cd1 = -11.451; + const double cd2 = -442.1533; + + complex_type a(cd1, cd2); + double d; + d = a.real(); + VERIFY( d == cd1 ); + + d = a.imag(); + VERIFY( d == cd2 ); + + complex_type c(cd1, cd2); + double d6 = abs(c); + VERIFY( d6 >= 0 ); + + double d7 = arg(c); + double d8 = atan2(c.imag(), c.real()); + VERIFY( d7 == d8 ); + + double d9 = norm(c); + double d10 = d6 * d6; + VERIFY( d9 - d10 == 0 ); + + complex_type e __attribute__((unused)) = conj(c); + + complex_type f = polar(c.imag(), 0.0); + VERIFY( f.real() != 0 ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/value_operations/constexpr.cc b/libstdc++-v3/testsuite/26_numerics/complex/value_operations/constexpr.cc new file mode 100644 index 000000000..29728a2b3 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/value_operations/constexpr.cc @@ -0,0 +1,57 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_functions + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + typedef typename _Ttesttype::_ComplexT _ComplexT; + const _ComplexT cc = { 1.1 }; + constexpr _Ttesttype a(cc); + constexpr auto v1 __attribute__((unused)) = real(a); + constexpr auto v2 __attribute__((unused)) = imag(a); + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_functions test; + test.operator()<std::complex<float>>(); + test.operator()<std::complex<double>>(); + test.operator()<std::complex<long double>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/value_operations/dr387.cc b/libstdc++-v3/testsuite/26_numerics/complex/value_operations/dr387.cc new file mode 100644 index 000000000..084a52c31 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/value_operations/dr387.cc @@ -0,0 +1,51 @@ +// 2008-05-22 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <complex> +#include <testsuite_hooks.h> + +// DR 387. std::complex over-encapsulated. +template<typename T> + void + do_test() + { + bool test __attribute__((unused)) = true; + + const T r = 1.0; + const T i = -1.0; + const T v = 0.0; + + std::complex<T> z1(r, i); + z1.real(v); + VERIFY( z1.real() == v ); + VERIFY( z1.imag() == i ); + + std::complex<T> z2(r, i); + z2.imag(v); + VERIFY( z2.real() == r ); + VERIFY( z2.imag() == v ); + } + +int main() +{ + do_test<float>(); + do_test<double>(); + do_test<long double>(); + return 0; +} |