summaryrefslogtreecommitdiff
path: root/test/std/numerics/complex.number/complex.value.ops
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/numerics/complex.number/complex.value.ops')
-rw-r--r--test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp63
-rw-r--r--test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp135
-rw-r--r--test/std/numerics/complex.number/complex.value.ops/conj.pass.cpp41
-rw-r--r--test/std/numerics/complex.number/complex.value.ops/imag.pass.cpp32
-rw-r--r--test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp63
-rw-r--r--test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp112
-rw-r--r--test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp71
-rw-r--r--test/std/numerics/complex.number/complex.value.ops/real.pass.cpp32
8 files changed, 549 insertions, 0 deletions
diff --git a/test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp
new file mode 100644
index 0000000000000..5d841d6ee9f10
--- /dev/null
+++ b/test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// template<class T>
+// T
+// abs(const complex<T>& x);
+
+#include <complex>
+#include <cassert>
+
+#include "../cases.h"
+
+template <class T>
+void
+test()
+{
+ std::complex<T> z(3, 4);
+ assert(abs(z) == 5);
+}
+
+void test_edges()
+{
+ const unsigned N = sizeof(x) / sizeof(x[0]);
+ for (unsigned i = 0; i < N; ++i)
+ {
+ double r = abs(x[i]);
+ switch (classify(x[i]))
+ {
+ case zero:
+ assert(r == 0);
+ assert(!std::signbit(r));
+ break;
+ case non_zero:
+ assert(std::isfinite(r) && r > 0);
+ break;
+ case inf:
+ assert(std::isinf(r) && r > 0);
+ break;
+ case NaN:
+ assert(std::isnan(r));
+ break;
+ case non_zero_nan:
+ assert(std::isnan(r));
+ break;
+ }
+ }
+}
+
+int main()
+{
+ test<float>();
+ test<double>();
+ test<long double>();
+ test_edges();
+}
diff --git a/test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp
new file mode 100644
index 0000000000000..a7da456b979c1
--- /dev/null
+++ b/test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp
@@ -0,0 +1,135 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// template<class T>
+// T
+// arg(const complex<T>& x);
+
+#include <complex>
+#include <cassert>
+
+#include "../cases.h"
+
+template <class T>
+void
+test()
+{
+ std::complex<T> z(1, 0);
+ assert(arg(z) == 0);
+}
+
+void test_edges()
+{
+ const double pi = std::atan2(+0., -0.);
+ const unsigned N = sizeof(x) / sizeof(x[0]);
+ for (unsigned i = 0; i < N; ++i)
+ {
+ double r = arg(x[i]);
+ if (std::isnan(x[i].real()) || std::isnan(x[i].imag()))
+ assert(std::isnan(r));
+ else
+ {
+ switch (classify(x[i]))
+ {
+ case zero:
+ if (std::signbit(x[i].real()))
+ {
+ if (std::signbit(x[i].imag()))
+ is_about(r, -pi);
+ else
+ is_about(r, pi);
+ }
+ else
+ {
+ assert(std::signbit(x[i].imag()) == std::signbit(r));
+ }
+ break;
+ case non_zero:
+ if (x[i].real() == 0)
+ {
+ if (x[i].imag() < 0)
+ is_about(r, -pi/2);
+ else
+ is_about(r, pi/2);
+ }
+ else if (x[i].imag() == 0)
+ {
+ if (x[i].real() < 0)
+ {
+ if (std::signbit(x[i].imag()))
+ is_about(r, -pi);
+ else
+ is_about(r, pi);
+ }
+ else
+ {
+ assert(r == 0);
+ assert(std::signbit(x[i].imag()) == std::signbit(r));
+ }
+ }
+ else if (x[i].imag() > 0)
+ assert(r > 0);
+ else
+ assert(r < 0);
+ break;
+ case inf:
+ if (std::isinf(x[i].real()) && std::isinf(x[i].imag()))
+ {
+ if (x[i].real() < 0)
+ {
+ if (x[i].imag() > 0)
+ is_about(r, 0.75 * pi);
+ else
+ is_about(r, -0.75 * pi);
+ }
+ else
+ {
+ if (x[i].imag() > 0)
+ is_about(r, 0.25 * pi);
+ else
+ is_about(r, -0.25 * pi);
+ }
+ }
+ else if (std::isinf(x[i].real()))
+ {
+ if (x[i].real() < 0)
+ {
+ if (std::signbit(x[i].imag()))
+ is_about(r, -pi);
+ else
+ is_about(r, pi);
+ }
+ else
+ {
+ assert(r == 0);
+ assert(std::signbit(r) == std::signbit(x[i].imag()));
+ }
+ }
+ else
+ {
+ if (x[i].imag() < 0)
+ is_about(r, -pi/2);
+ else
+ is_about(r, pi/2);
+ }
+ break;
+ }
+ }
+ }
+}
+
+int main()
+{
+ test<float>();
+ test<double>();
+ test<long double>();
+ test_edges();
+}
diff --git a/test/std/numerics/complex.number/complex.value.ops/conj.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/conj.pass.cpp
new file mode 100644
index 0000000000000..71f276d8d4709
--- /dev/null
+++ b/test/std/numerics/complex.number/complex.value.ops/conj.pass.cpp
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// template<class T>
+// complex<T>
+// conj(const complex<T>& x);
+
+#include <complex>
+#include <cassert>
+
+template <class T>
+void
+test(const std::complex<T>& z, std::complex<T> x)
+{
+ assert(conj(z) == x);
+}
+
+template <class T>
+void
+test()
+{
+ test(std::complex<T>(1, 2), std::complex<T>(1, -2));
+ test(std::complex<T>(-1, 2), std::complex<T>(-1, -2));
+ test(std::complex<T>(1, -2), std::complex<T>(1, 2));
+ test(std::complex<T>(-1, -2), std::complex<T>(-1, 2));
+}
+
+int main()
+{
+ test<float>();
+ test<double>();
+ test<long double>();
+}
diff --git a/test/std/numerics/complex.number/complex.value.ops/imag.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/imag.pass.cpp
new file mode 100644
index 0000000000000..fa7b7339a6d48
--- /dev/null
+++ b/test/std/numerics/complex.number/complex.value.ops/imag.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// template<class T>
+// T
+// imag(const complex<T>& x);
+
+#include <complex>
+#include <cassert>
+
+template <class T>
+void
+test()
+{
+ std::complex<T> z(1.5, 2.5);
+ assert(imag(z) == 2.5);
+}
+
+int main()
+{
+ test<float>();
+ test<double>();
+ test<long double>();
+}
diff --git a/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp
new file mode 100644
index 0000000000000..48f774e8e1c92
--- /dev/null
+++ b/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// template<class T>
+// T
+// norm(const complex<T>& x);
+
+#include <complex>
+#include <cassert>
+
+#include "../cases.h"
+
+template <class T>
+void
+test()
+{
+ std::complex<T> z(3, 4);
+ assert(norm(z) == 25);
+}
+
+void test_edges()
+{
+ const unsigned N = sizeof(x) / sizeof(x[0]);
+ for (unsigned i = 0; i < N; ++i)
+ {
+ double r = norm(x[i]);
+ switch (classify(x[i]))
+ {
+ case zero:
+ assert(r == 0);
+ assert(!std::signbit(r));
+ break;
+ case non_zero:
+ assert(std::isfinite(r) && r > 0);
+ break;
+ case inf:
+ assert(std::isinf(r) && r > 0);
+ break;
+ case NaN:
+ assert(std::isnan(r));
+ break;
+ case non_zero_nan:
+ assert(std::isnan(r));
+ break;
+ }
+ }
+}
+
+int main()
+{
+ test<float>();
+ test<double>();
+ test<long double>();
+ test_edges();
+}
diff --git a/test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp
new file mode 100644
index 0000000000000..a8747bd7c83b4
--- /dev/null
+++ b/test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp
@@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// template<class T>
+// complex<T>
+// polar(const T& rho, const T& theta = 0);
+
+#include <complex>
+#include <cassert>
+
+#include "../cases.h"
+
+template <class T>
+void
+test(const T& rho, std::complex<T> x)
+{
+ assert(std::polar(rho) == x);
+}
+
+template <class T>
+void
+test(const T& rho, const T& theta, std::complex<T> x)
+{
+ assert(std::polar(rho, theta) == x);
+}
+
+template <class T>
+void
+test()
+{
+ test(T(0), std::complex<T>(0, 0));
+ test(T(1), std::complex<T>(1, 0));
+ test(T(100), std::complex<T>(100, 0));
+ test(T(0), T(0), std::complex<T>(0, 0));
+ test(T(1), T(0), std::complex<T>(1, 0));
+ test(T(100), T(0), std::complex<T>(100, 0));
+}
+
+void test_edges()
+{
+ const unsigned N = sizeof(x) / sizeof(x[0]);
+ for (unsigned i = 0; i < N; ++i)
+ {
+ double r = real(x[i]);
+ double theta = imag(x[i]);
+ std::complex<double> z = std::polar(r, theta);
+ switch (classify(r))
+ {
+ case zero:
+ if (std::signbit(r) || classify(theta) == inf || classify(theta) == NaN)
+ {
+ int c = classify(z);
+ assert(c == NaN || c == non_zero_nan);
+ }
+ else
+ {
+ assert(z == std::complex<double>());
+ }
+ break;
+ case non_zero:
+ if (std::signbit(r) || classify(theta) == inf || classify(theta) == NaN)
+ {
+ int c = classify(z);
+ assert(c == NaN || c == non_zero_nan);
+ }
+ else
+ {
+ is_about(std::abs(z), r);
+ }
+ break;
+ case inf:
+ if (r < 0)
+ {
+ int c = classify(z);
+ assert(c == NaN || c == non_zero_nan);
+ }
+ else
+ {
+ assert(classify(z) == inf);
+ if (classify(theta) != NaN && classify(theta) != inf)
+ {
+ assert(classify(real(z)) != NaN);
+ assert(classify(imag(z)) != NaN);
+ }
+ }
+ break;
+ case NaN:
+ case non_zero_nan:
+ {
+ int c = classify(z);
+ assert(c == NaN || c == non_zero_nan);
+ }
+ break;
+ }
+ }
+}
+
+int main()
+{
+ test<float>();
+ test<double>();
+ test<long double>();
+ test_edges();
+}
diff --git a/test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp
new file mode 100644
index 0000000000000..10bf7f8576f6b
--- /dev/null
+++ b/test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// template<class T>
+// complex<T>
+// proj(const complex<T>& x);
+
+#include <complex>
+#include <cassert>
+
+#include "../cases.h"
+
+template <class T>
+void
+test(const std::complex<T>& z, std::complex<T> x)
+{
+ assert(proj(z) == x);
+}
+
+template <class T>
+void
+test()
+{
+ test(std::complex<T>(1, 2), std::complex<T>(1, 2));
+ test(std::complex<T>(-1, 2), std::complex<T>(-1, 2));
+ test(std::complex<T>(1, -2), std::complex<T>(1, -2));
+ test(std::complex<T>(-1, -2), std::complex<T>(-1, -2));
+}
+
+void test_edges()
+{
+ const unsigned N = sizeof(x) / sizeof(x[0]);
+ for (unsigned i = 0; i < N; ++i)
+ {
+ std::complex<double> r = proj(x[i]);
+ switch (classify(x[i]))
+ {
+ case zero:
+ case non_zero:
+ assert(r == x[i]);
+ assert(std::signbit(real(r)) == std::signbit(real(x[i])));
+ assert(std::signbit(imag(r)) == std::signbit(imag(x[i])));
+ break;
+ case inf:
+ assert(std::isinf(real(r)) && real(r) > 0);
+ assert(imag(r) == 0);
+ assert(std::signbit(imag(r)) == std::signbit(imag(x[i])));
+ break;
+ case NaN:
+ case non_zero_nan:
+ assert(classify(r) == classify(x[i]));
+ break;
+ }
+ }
+}
+
+int main()
+{
+ test<float>();
+ test<double>();
+ test<long double>();
+ test_edges();
+}
diff --git a/test/std/numerics/complex.number/complex.value.ops/real.pass.cpp b/test/std/numerics/complex.number/complex.value.ops/real.pass.cpp
new file mode 100644
index 0000000000000..fbb51f0806406
--- /dev/null
+++ b/test/std/numerics/complex.number/complex.value.ops/real.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// template<class T>
+// T
+// real(const complex<T>& x);
+
+#include <complex>
+#include <cassert>
+
+template <class T>
+void
+test()
+{
+ std::complex<T> z(1.5, 2.5);
+ assert(real(z) == 1.5);
+}
+
+int main()
+{
+ test<float>();
+ test<double>();
+ test<long double>();
+}