Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <cmath>
// isinf
// XFAIL: linux
#include <cmath>
#include <type_traits>
#include <cassert>
int main()
{
#ifdef isinf
#error isinf defined
#endif
static_assert((std::is_same<decltype(std::isinf((float)0)), bool>::value), "");
static_assert((std::is_same<decltype(std::isinf((double)0)), bool>::value), "");
static_assert((std::is_same<decltype(std::isinf(0)), bool>::value), "");
static_assert((std::is_same<decltype(std::isinf((long double)0)), bool>::value), "");
assert(std::isinf(-1.0) == false);
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <cmath>
// isnan
// XFAIL: linux
#include <cmath>
#include <type_traits>
#include <cassert>
int main()
{
#ifdef isnan
#error isnan defined
#endif
static_assert((std::is_same<decltype(std::isnan((float)0)), bool>::value), "");
static_assert((std::is_same<decltype(std::isnan((double)0)), bool>::value), "");
static_assert((std::is_same<decltype(std::isnan(0)), bool>::value), "");
static_assert((std::is_same<decltype(std::isnan((long double)0)), bool>::value), "");
assert(std::isnan(-1.0) == false);
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <ctgmath>
#include <ctgmath>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
std::complex<double> cd;
double x = std::sin(0);
}

View File

@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tgmath.h>
#include <tgmath.h>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}

View File

@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <cmath>
#include <cmath>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}

View File

@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: newlib
// <cfenv>
#include <cfenv>
#include <type_traits>
#ifndef FE_DIVBYZERO
#error FE_DIVBYZERO not defined
#endif
#ifndef FE_INEXACT
#error FE_INEXACT not defined
#endif
#ifndef FE_INVALID
#error FE_INVALID not defined
#endif
#ifndef FE_OVERFLOW
#error FE_OVERFLOW not defined
#endif
#ifndef FE_UNDERFLOW
#error FE_UNDERFLOW not defined
#endif
#ifndef FE_ALL_EXCEPT
#error FE_ALL_EXCEPT not defined
#endif
#ifndef FE_DOWNWARD
#error FE_DOWNWARD not defined
#endif
#ifndef FE_TONEAREST
#error FE_TONEAREST not defined
#endif
#ifndef FE_TOWARDZERO
#error FE_TOWARDZERO not defined
#endif
#ifndef FE_UPWARD
#error FE_UPWARD not defined
#endif
#ifndef FE_DFL_ENV
#error FE_DFL_ENV not defined
#endif
int main()
{
std::fenv_t fenv = {0};
std::fexcept_t fex = 0;
static_assert((std::is_same<decltype(std::feclearexcept(0)), int>::value), "");
static_assert((std::is_same<decltype(std::fegetexceptflag(&fex, 0)), int>::value), "");
static_assert((std::is_same<decltype(std::feraiseexcept(0)), int>::value), "");
static_assert((std::is_same<decltype(std::fesetexceptflag(&fex, 0)), int>::value), "");
static_assert((std::is_same<decltype(std::fetestexcept(0)), int>::value), "");
static_assert((std::is_same<decltype(std::fegetround()), int>::value), "");
static_assert((std::is_same<decltype(std::fesetround(0)), int>::value), "");
static_assert((std::is_same<decltype(std::fegetenv(&fenv)), int>::value), "");
static_assert((std::is_same<decltype(std::feholdexcept(&fenv)), int>::value), "");
static_assert((std::is_same<decltype(std::fesetenv(&fenv)), int>::value), "");
static_assert((std::is_same<decltype(std::feupdateenv(&fenv)), int>::value), "");
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: newlib
// <cfenv>
#include <cfenv>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}

View File

@@ -0,0 +1,230 @@
//===----------------------------------------------------------------------===//
//
// 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>
// test cases
#ifndef CASES_H
#define CASES_H
#include <complex>
#include <cassert>
std::complex<double> x[] =
{
std::complex<double>( 1.e-6, 1.e-6),
std::complex<double>(-1.e-6, 1.e-6),
std::complex<double>(-1.e-6, -1.e-6),
std::complex<double>( 1.e-6, -1.e-6),
std::complex<double>( 1.e+6, 1.e-6),
std::complex<double>(-1.e+6, 1.e-6),
std::complex<double>(-1.e+6, -1.e-6),
std::complex<double>( 1.e+6, -1.e-6),
std::complex<double>( 1.e-6, 1.e+6),
std::complex<double>(-1.e-6, 1.e+6),
std::complex<double>(-1.e-6, -1.e+6),
std::complex<double>( 1.e-6, -1.e+6),
std::complex<double>( 1.e+6, 1.e+6),
std::complex<double>(-1.e+6, 1.e+6),
std::complex<double>(-1.e+6, -1.e+6),
std::complex<double>( 1.e+6, -1.e+6),
std::complex<double>(NAN, NAN),
std::complex<double>(-INFINITY, NAN),
std::complex<double>(-2, NAN),
std::complex<double>(-1, NAN),
std::complex<double>(-0.5, NAN),
std::complex<double>(-0., NAN),
std::complex<double>(+0., NAN),
std::complex<double>(0.5, NAN),
std::complex<double>(1, NAN),
std::complex<double>(2, NAN),
std::complex<double>(INFINITY, NAN),
std::complex<double>(NAN, -INFINITY),
std::complex<double>(-INFINITY, -INFINITY),
std::complex<double>(-2, -INFINITY),
std::complex<double>(-1, -INFINITY),
std::complex<double>(-0.5, -INFINITY),
std::complex<double>(-0., -INFINITY),
std::complex<double>(+0., -INFINITY),
std::complex<double>(0.5, -INFINITY),
std::complex<double>(1, -INFINITY),
std::complex<double>(2, -INFINITY),
std::complex<double>(INFINITY, -INFINITY),
std::complex<double>(NAN, -2),
std::complex<double>(-INFINITY, -2),
std::complex<double>(-2, -2),
std::complex<double>(-1, -2),
std::complex<double>(-0.5, -2),
std::complex<double>(-0., -2),
std::complex<double>(+0., -2),
std::complex<double>(0.5, -2),
std::complex<double>(1, -2),
std::complex<double>(2, -2),
std::complex<double>(INFINITY, -2),
std::complex<double>(NAN, -1),
std::complex<double>(-INFINITY, -1),
std::complex<double>(-2, -1),
std::complex<double>(-1, -1),
std::complex<double>(-0.5, -1),
std::complex<double>(-0., -1),
std::complex<double>(+0., -1),
std::complex<double>(0.5, -1),
std::complex<double>(1, -1),
std::complex<double>(2, -1),
std::complex<double>(INFINITY, -1),
std::complex<double>(NAN, -0.5),
std::complex<double>(-INFINITY, -0.5),
std::complex<double>(-2, -0.5),
std::complex<double>(-1, -0.5),
std::complex<double>(-0.5, -0.5),
std::complex<double>(-0., -0.5),
std::complex<double>(+0., -0.5),
std::complex<double>(0.5, -0.5),
std::complex<double>(1, -0.5),
std::complex<double>(2, -0.5),
std::complex<double>(INFINITY, -0.5),
std::complex<double>(NAN, -0.),
std::complex<double>(-INFINITY, -0.),
std::complex<double>(-2, -0.),
std::complex<double>(-1, -0.),
std::complex<double>(-0.5, -0.),
std::complex<double>(-0., -0.),
std::complex<double>(+0., -0.),
std::complex<double>(0.5, -0.),
std::complex<double>(1, -0.),
std::complex<double>(2, -0.),
std::complex<double>(INFINITY, -0.),
std::complex<double>(NAN, +0.),
std::complex<double>(-INFINITY, +0.),
std::complex<double>(-2, +0.),
std::complex<double>(-1, +0.),
std::complex<double>(-0.5, +0.),
std::complex<double>(-0., +0.),
std::complex<double>(+0., +0.),
std::complex<double>(0.5, +0.),
std::complex<double>(1, +0.),
std::complex<double>(2, +0.),
std::complex<double>(INFINITY, +0.),
std::complex<double>(NAN, 0.5),
std::complex<double>(-INFINITY, 0.5),
std::complex<double>(-2, 0.5),
std::complex<double>(-1, 0.5),
std::complex<double>(-0.5, 0.5),
std::complex<double>(-0., 0.5),
std::complex<double>(+0., 0.5),
std::complex<double>(0.5, 0.5),
std::complex<double>(1, 0.5),
std::complex<double>(2, 0.5),
std::complex<double>(INFINITY, 0.5),
std::complex<double>(NAN, 1),
std::complex<double>(-INFINITY, 1),
std::complex<double>(-2, 1),
std::complex<double>(-1, 1),
std::complex<double>(-0.5, 1),
std::complex<double>(-0., 1),
std::complex<double>(+0., 1),
std::complex<double>(0.5, 1),
std::complex<double>(1, 1),
std::complex<double>(2, 1),
std::complex<double>(INFINITY, 1),
std::complex<double>(NAN, 2),
std::complex<double>(-INFINITY, 2),
std::complex<double>(-2, 2),
std::complex<double>(-1, 2),
std::complex<double>(-0.5, 2),
std::complex<double>(-0., 2),
std::complex<double>(+0., 2),
std::complex<double>(0.5, 2),
std::complex<double>(1, 2),
std::complex<double>(2, 2),
std::complex<double>(INFINITY, 2),
std::complex<double>(NAN, INFINITY),
std::complex<double>(-INFINITY, INFINITY),
std::complex<double>(-2, INFINITY),
std::complex<double>(-1, INFINITY),
std::complex<double>(-0.5, INFINITY),
std::complex<double>(-0., INFINITY),
std::complex<double>(+0., INFINITY),
std::complex<double>(0.5, INFINITY),
std::complex<double>(1, INFINITY),
std::complex<double>(2, INFINITY),
std::complex<double>(INFINITY, INFINITY)
};
enum {zero, non_zero, inf, NaN, non_zero_nan};
template <class T>
int
classify(const std::complex<T>& x)
{
if (x == std::complex<T>())
return zero;
if (std::isinf(x.real()) || std::isinf(x.imag()))
return inf;
if (std::isnan(x.real()) && std::isnan(x.imag()))
return NaN;
if (std::isnan(x.real()))
{
if (x.imag() == T(0))
return NaN;
return non_zero_nan;
}
if (std::isnan(x.imag()))
{
if (x.real() == T(0))
return NaN;
return non_zero_nan;
}
return non_zero;
}
inline
int
classify(double x)
{
if (x == 0)
return zero;
if (std::isinf(x))
return inf;
if (std::isnan(x))
return NaN;
return non_zero;
}
void is_about(float x, float y)
{
assert(std::abs((x-y)/(x+y)) < 1.e-6);
}
void is_about(double x, double y)
{
assert(std::abs((x-y)/(x+y)) < 1.e-14);
}
void is_about(long double x, long double y)
{
assert(std::abs((x-y)/(x+y)) < 1.e-14);
}
#endif // CASES_H

View File

@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <ccomplex>
#include <ccomplex>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
std::complex<double> d;
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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<Arithmetic T>
// T
// arg(T x);
#include <complex>
#include <type_traits>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::arg(x)), double>::value), "");
assert(std::arg(x) == arg(std::complex<double>(x, 0)));
}
template <class T>
void
test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::arg(x)), T>::value), "");
assert(std::arg(x) == arg(std::complex<T>(x, 0)));
}
template <class T>
void
test()
{
test<T>(0);
test<T>(1);
test<T>(10);
}
int main()
{
test<float>();
test<double>();
test<long double>();
test<int>();
test<unsigned>();
test<long long>();
}

View File

@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// 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>&);
// complex<long double> conj(long double);
// complex<double> conj(double);
// template<Integral T> complex<double> conj(T);
// complex<float> conj(float);
#include <complex>
#include <type_traits>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::conj(x)), std::complex<double> >::value), "");
assert(std::conj(x) == conj(std::complex<double>(x, 0)));
}
template <class T>
void
test(T x, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::conj(x)), std::complex<T> >::value), "");
assert(std::conj(x) == conj(std::complex<T>(x, 0)));
}
template <class T>
void
test(T x, typename std::enable_if<!std::is_integral<T>::value &&
!std::is_floating_point<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::conj(x)), std::complex<T> >::value), "");
assert(std::conj(x) == conj(std::complex<T>(x, 0)));
}
template <class T>
void
test()
{
test<T>(0);
test<T>(1);
test<T>(10);
}
int main()
{
test<float>();
test<double>();
test<long double>();
test<int>();
test<unsigned>();
test<long long>();
}

View File

@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// 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<Arithmetic T>
// T
// imag(const T& x);
#include <complex>
#include <type_traits>
#include <cassert>
#include "../cases.h"
template <class T, int x>
void
test(typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::imag(T(x))), double>::value), "");
assert(std::imag(x) == 0);
#if _LIBCPP_STD_VER > 11
constexpr T val {x};
static_assert(std::imag(val) == 0, "");
constexpr std::complex<T> t{val, val};
static_assert(t.imag() == x, "" );
#endif
}
template <class T, int x>
void
test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::imag(T(x))), T>::value), "");
assert(std::imag(x) == 0);
#if _LIBCPP_STD_VER > 11
constexpr T val {x};
static_assert(std::imag(val) == 0, "");
constexpr std::complex<T> t{val, val};
static_assert(t.imag() == x, "" );
#endif
}
template <class T>
void
test()
{
test<T, 0>();
test<T, 1>();
test<T, 10>();
}
int main()
{
test<float>();
test<double>();
test<long double>();
test<int>();
test<unsigned>();
test<long long>();
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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<Arithmetic T>
// T
// norm(T x);
#include <complex>
#include <type_traits>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::norm(x)), double>::value), "");
assert(std::norm(x) == norm(std::complex<double>(x, 0)));
}
template <class T>
void
test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::norm(x)), T>::value), "");
assert(std::norm(x) == norm(std::complex<T>(x, 0)));
}
template <class T>
void
test()
{
test<T>(0);
test<T>(1);
test<T>(10);
}
int main()
{
test<float>();
test<double>();
test<long double>();
test<int>();
test<unsigned>();
test<long long>();
}

View File

@@ -0,0 +1,104 @@
//===----------------------------------------------------------------------===//
//
// 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<Arithmetic T, Arithmetic U>
// complex<promote<T, U>::type>
// pow(const T& x, const complex<U>& y);
// template<Arithmetic T, Arithmetic U>
// complex<promote<T, U>::type>
// pow(const complex<T>& x, const U& y);
// template<Arithmetic T, Arithmetic U>
// complex<promote<T, U>::type>
// pow(const complex<T>& x, const complex<U>& y);
#include <complex>
#include <type_traits>
#include <cassert>
#include "../cases.h"
template <class T>
double
promote(T, typename std::enable_if<std::is_integral<T>::value>::type* = 0);
float promote(float);
double promote(double);
long double promote(long double);
template <class T, class U>
void
test(T x, const std::complex<U>& y)
{
typedef decltype(promote(x)+promote(real(y))) V;
static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
assert(std::pow(x, y) == pow(std::complex<V>(x, 0), std::complex<V>(y)));
}
template <class T, class U>
void
test(const std::complex<T>& x, U y)
{
typedef decltype(promote(real(x))+promote(y)) V;
static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
assert(std::pow(x, y) == pow(std::complex<V>(x), std::complex<V>(y, 0)));
}
template <class T, class U>
void
test(const std::complex<T>& x, const std::complex<U>& y)
{
typedef decltype(promote(real(x))+promote(real(y))) V;
static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
assert(std::pow(x, y) == pow(std::complex<V>(x), std::complex<V>(y)));
}
template <class T, class U>
void
test(typename std::enable_if<std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0)
{
test(T(3), std::complex<U>(4, 5));
test(std::complex<U>(3, 4), T(5));
}
template <class T, class U>
void
test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0)
{
test(T(3), std::complex<U>(4, 5));
test(std::complex<T>(3, 4), U(5));
test(std::complex<T>(3, 4), std::complex<U>(5, 6));
}
int main()
{
test<int, float>();
test<int, double>();
test<int, long double>();
test<unsigned, float>();
test<unsigned, double>();
test<unsigned, long double>();
test<long long, float>();
test<long long, double>();
test<long long, long double>();
test<float, double>();
test<float, long double>();
test<double, float>();
test<double, long double>();
test<long double, float>();
test<long double, double>();
}

View File

@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// 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>&);
// complex<long double> proj(long double);
// complex<double> proj(double);
// template<Integral T> complex<double> proj(T);
// complex<float> proj(float);
#include <complex>
#include <type_traits>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::proj(x)), std::complex<double> >::value), "");
assert(std::proj(x) == proj(std::complex<double>(x, 0)));
}
template <class T>
void
test(T x, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::proj(x)), std::complex<T> >::value), "");
assert(std::proj(x) == proj(std::complex<T>(x, 0)));
}
template <class T>
void
test(T x, typename std::enable_if<!std::is_integral<T>::value &&
!std::is_floating_point<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::proj(x)), std::complex<T> >::value), "");
assert(std::proj(x) == proj(std::complex<T>(x, 0)));
}
template <class T>
void
test()
{
test<T>(0);
test<T>(1);
test<T>(10);
}
int main()
{
test<float>();
test<double>();
test<long double>();
test<int>();
test<unsigned>();
test<long long>();
}

View File

@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// 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<Arithmetic T>
// T
// real(const T& x);
#include <complex>
#include <type_traits>
#include <cassert>
#include "../cases.h"
template <class T, int x>
void
test(typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::real(T(x))), double>::value), "");
assert(std::real(x) == x);
#if _LIBCPP_STD_VER > 11
constexpr T val {x};
static_assert(std::real(val) == val, "");
constexpr std::complex<T> t{val, val};
static_assert(t.real() == x, "" );
#endif
}
template <class T, int x>
void
test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
{
static_assert((std::is_same<decltype(std::real(T(x))), T>::value), "");
assert(std::real(x) == x);
#if _LIBCPP_STD_VER > 11
constexpr T val {x};
static_assert(std::real(val) == val, "");
constexpr std::complex<T> t{val, val};
static_assert(t.real() == x, "" );
#endif
}
template <class T>
void
test()
{
test<T, 0>();
test<T, 1>();
test<T, 10>();
}
int main()
{
test<float>();
test<double>();
test<long double>();
test<int>();
test<unsigned>();
test<long long>();
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <chrono>
#include <complex>
#include <type_traits>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
using namespace std::literals::complex_literals;
// Make sure the types are right
static_assert ( std::is_same<decltype( 3.0il ), std::complex<long double>>::value, "" );
static_assert ( std::is_same<decltype( 3il ), std::complex<long double>>::value, "" );
static_assert ( std::is_same<decltype( 3.0i ), std::complex<double>>::value, "" );
static_assert ( std::is_same<decltype( 3i ), std::complex<double>>::value, "" );
static_assert ( std::is_same<decltype( 3.0if ), std::complex<float>>::value, "" );
static_assert ( std::is_same<decltype( 3if ), std::complex<float>>::value, "" );
{
std::complex<long double> c1 = 3.0il;
assert ( c1 == std::complex<long double>(0, 3.0));
auto c2 = 3il;
assert ( c1 == c2 );
}
{
std::complex<double> c1 = 3.0i;
assert ( c1 == std::complex<double>(0, 3.0));
auto c2 = 3i;
assert ( c1 == c2 );
}
{
std::complex<float> c1 = 3.0if;
assert ( c1 == std::complex<float>(0, 3.0));
auto c2 = 3if;
assert ( c1 == c2 );
}
#endif
}

View File

@@ -0,0 +1,20 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#include <complex>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
std::complex<float> foo = 1.0if; // should fail w/conversion operator not found
#else
#error
#endif
}

View File

@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <chrono>
#include <complex>
#include <type_traits>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
using namespace std::literals;
{
std::complex<long double> c1 = 3.0il;
assert ( c1 == std::complex<long double>(0, 3.0));
auto c2 = 3il;
assert ( c1 == c2 );
}
{
std::complex<double> c1 = 3.0i;
assert ( c1 == std::complex<double>(0, 3.0));
auto c2 = 3i;
assert ( c1 == c2 );
}
{
std::complex<float> c1 = 3.0if;
assert ( c1 == std::complex<float>(0, 3.0));
auto c2 = 3if;
assert ( c1 == c2 );
}
#endif
}

View File

@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <chrono>
#include <complex>
#include <type_traits>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
using namespace std;
{
std::complex<long double> c1 = 3.0il;
assert ( c1 == std::complex<long double>(0, 3.0));
auto c2 = 3il;
assert ( c1 == c2 );
}
{
std::complex<double> c1 = 3.0i;
assert ( c1 == std::complex<double>(0, 3.0));
auto c2 = 3i;
assert ( c1 == c2 );
}
{
std::complex<float> c1 = 3.0if;
assert ( c1 == std::complex<float>(0, 3.0));
auto c2 = 3if;
assert ( c1 == c2 );
}
#endif
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator=(const complex&);
// template<class X> complex& operator= (const complex<X>&);
#include <complex>
#include <cassert>
template <class T, class X>
void
test()
{
std::complex<T> c;
assert(c.real() == 0);
assert(c.imag() == 0);
std::complex<T> c2(1.5, 2.5);
c = c2;
assert(c.real() == 1.5);
assert(c.imag() == 2.5);
std::complex<X> c3(3.5, -4.5);
c = c3;
assert(c.real() == 3.5);
assert(c.imag() == -4.5);
}
int main()
{
test<float, float>();
test<float, double>();
test<float, long double>();
test<double, float>();
test<double, double>();
test<double, long double>();
test<long double, float>();
test<long double, double>();
test<long double, long double>();
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator= (const T&);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c;
assert(c.real() == 0);
assert(c.imag() == 0);
c = 1.5;
assert(c.real() == 1.5);
assert(c.imag() == 0);
c = -1.5;
assert(c.real() == -1.5);
assert(c.imag() == 0);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator/=(const complex& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c(-4, 7.5);
const std::complex<T> c2(1.5, 2.5);
assert(c.real() == -4);
assert(c.imag() == 7.5);
c /= c2;
assert(c.real() == 1.5);
assert(c.imag() == 2.5);
c /= c2;
assert(c.real() == 1);
assert(c.imag() == 0);
std::complex<T> c3;
c3 = c;
std::complex<int> ic (1,1);
c3 /= ic;
assert(c3.real() == 0.5);
assert(c3.imag() == -0.5);
c3 = c;
std::complex<float> fc (1,1);
c3 /= fc;
assert(c3.real() == 0.5);
assert(c3.imag() == -0.5);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator/=(const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c(1);
assert(c.real() == 1);
assert(c.imag() == 0);
c /= 0.5;
assert(c.real() == 2);
assert(c.imag() == 0);
c /= 0.5;
assert(c.real() == 4);
assert(c.imag() == 0);
c /= -0.5;
assert(c.real() == -8);
assert(c.imag() == 0);
c.imag(2);
c /= 0.5;
assert(c.real() == -16);
assert(c.imag() == 4);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator-=(const complex& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c;
const std::complex<T> c2(1.5, 2.5);
assert(c.real() == 0);
assert(c.imag() == 0);
c -= c2;
assert(c.real() == -1.5);
assert(c.imag() == -2.5);
c -= c2;
assert(c.real() == -3);
assert(c.imag() == -5);
std::complex<T> c3;
c3 = c;
std::complex<int> ic (1,1);
c3 -= ic;
assert(c3.real() == -4);
assert(c3.imag() == -6);
c3 = c;
std::complex<float> fc (1,1);
c3 -= fc;
assert(c3.real() == -4);
assert(c3.imag() == -6);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator-=(const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c;
assert(c.real() == 0);
assert(c.imag() == 0);
c -= 1.5;
assert(c.real() == -1.5);
assert(c.imag() == 0);
c -= 1.5;
assert(c.real() == -3);
assert(c.imag() == 0);
c -= -1.5;
assert(c.real() == -1.5);
assert(c.imag() == 0);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator+=(const complex& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c;
const std::complex<T> c2(1.5, 2.5);
assert(c.real() == 0);
assert(c.imag() == 0);
c += c2;
assert(c.real() == 1.5);
assert(c.imag() == 2.5);
c += c2;
assert(c.real() == 3);
assert(c.imag() == 5);
std::complex<T> c3;
c3 = c;
std::complex<int> ic (1,1);
c3 += ic;
assert(c3.real() == 4);
assert(c3.imag() == 6);
c3 = c;
std::complex<float> fc (1,1);
c3 += fc;
assert(c3.real() == 4);
assert(c3.imag() == 6);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator+=(const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c;
assert(c.real() == 0);
assert(c.imag() == 0);
c += 1.5;
assert(c.real() == 1.5);
assert(c.imag() == 0);
c += 1.5;
assert(c.real() == 3);
assert(c.imag() == 0);
c += -1.5;
assert(c.real() == 1.5);
assert(c.imag() == 0);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator*=(const complex& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c(1);
const std::complex<T> c2(1.5, 2.5);
assert(c.real() == 1);
assert(c.imag() == 0);
c *= c2;
assert(c.real() == 1.5);
assert(c.imag() == 2.5);
c *= c2;
assert(c.real() == -4);
assert(c.imag() == 7.5);
std::complex<T> c3;
c3 = c;
std::complex<int> ic (1,1);
c3 *= ic;
assert(c3.real() == -11.5);
assert(c3.imag() == 3.5);
c3 = c;
std::complex<float> fc (1,1);
c3 *= fc;
assert(c3.real() == -11.5);
assert(c3.imag() == 3.5);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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>
// complex& operator*=(const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> c(1);
assert(c.real() == 1);
assert(c.imag() == 0);
c *= 1.5;
assert(c.real() == 1.5);
assert(c.imag() == 0);
c *= 1.5;
assert(c.real() == 2.25);
assert(c.imag() == 0);
c *= -1.5;
assert(c.real() == -3.375);
assert(c.imag() == 0);
c.imag(2);
c *= 1.5;
assert(c.real() == -5.0625);
assert(c.imag() == 3);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// 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>
// constexpr complex(const T& re = T(), const T& im = T());
#include <complex>
#include <cassert>
template <class T>
void
test()
{
{
const std::complex<T> c;
assert(c.real() == 0);
assert(c.imag() == 0);
}
{
const std::complex<T> c = 7.5;
assert(c.real() == 7.5);
assert(c.imag() == 0);
}
{
const std::complex<T> c(8.5);
assert(c.real() == 8.5);
assert(c.imag() == 0);
}
{
const std::complex<T> c(10.5, -9.5);
assert(c.real() == 10.5);
assert(c.imag() == -9.5);
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<T> c;
static_assert(c.real() == 0, "");
static_assert(c.imag() == 0, "");
}
{
constexpr std::complex<T> c = 7.5;
static_assert(c.real() == 7.5, "");
static_assert(c.imag() == 0, "");
}
{
constexpr std::complex<T> c(8.5);
static_assert(c.real() == 8.5, "");
static_assert(c.imag() == 0, "");
}
{
constexpr std::complex<T> c(10.5, -9.5);
static_assert(c.real() == 10.5, "");
static_assert(c.imag() == -9.5, "");
}
#endif
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void real(T val);
// void imag(T val);
#include <complex>
#include <cassert>
template <class T>
void
test_constexpr()
{
#if _LIBCPP_STD_VER > 11
constexpr std::complex<T> c1;
static_assert(c1.real() == 0, "");
static_assert(c1.imag() == 0, "");
constexpr std::complex<T> c2(3);
static_assert(c2.real() == 3, "");
static_assert(c2.imag() == 0, "");
constexpr std::complex<T> c3(3, 4);
static_assert(c3.real() == 3, "");
static_assert(c3.imag() == 4, "");
#endif
}
template <class T>
void
test()
{
std::complex<T> c;
assert(c.real() == 0);
assert(c.imag() == 0);
c.real(3.5);
assert(c.real() == 3.5);
assert(c.imag() == 0);
c.imag(4.5);
assert(c.real() == 3.5);
assert(c.imag() == 4.5);
c.real(-4.5);
assert(c.real() == -4.5);
assert(c.imag() == 4.5);
c.imag(-5.5);
assert(c.real() == -4.5);
assert(c.imag() == -5.5);
test_constexpr<T> ();
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_constexpr<int> ();
}

View File

@@ -0,0 +1,159 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator/(const complex<T>& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x)
{
assert(lhs / rhs == x);
}
template <class T>
void
test()
{
std::complex<T> lhs(-4.0, 7.5);
std::complex<T> rhs(1.5, 2.5);
std::complex<T> x(1.5, 2.5);
test(lhs, rhs, x);
}
void test_edges()
{
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
for (unsigned j = 0; j < N; ++j)
{
std::complex<double> r = x[i] / x[j];
switch (classify(x[i]))
{
case zero:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == NaN);
break;
case non_zero:
assert(classify(r) == zero);
break;
case inf:
assert(classify(r) == zero);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
case non_zero:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == inf);
break;
case non_zero:
assert(classify(r) == non_zero);
break;
case inf:
assert(classify(r) == zero);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
case inf:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == inf);
break;
case non_zero:
assert(classify(r) == inf);
break;
case inf:
assert(classify(r) == NaN);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
case NaN:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == NaN);
break;
case non_zero:
assert(classify(r) == NaN);
break;
case inf:
assert(classify(r) == NaN);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
case non_zero_nan:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == inf);
break;
case non_zero:
assert(classify(r) == NaN);
break;
case inf:
assert(classify(r) == NaN);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
}
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -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>
// operator/(const complex<T>& lhs, const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const std::complex<T>& lhs, const T& rhs, std::complex<T> x)
{
assert(lhs / rhs == x);
}
template <class T>
void
test()
{
std::complex<T> lhs(-4.0, 7.5);
T rhs(2);
std::complex<T> x(-2, 3.75);
test(lhs, rhs, x);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// 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>
// bool
// operator==(const complex<T>& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test_constexpr()
{
#if _LIBCPP_STD_VER > 11
{
constexpr std::complex<T> lhs(1.5, 2.5);
constexpr std::complex<T> rhs(1.5, -2.5);
static_assert( !(lhs == rhs), "");
}
{
constexpr std::complex<T> lhs(1.5, 2.5);
constexpr std::complex<T> rhs(1.5, 2.5);
static_assert(lhs == rhs, "");
}
#endif
}
template <class T>
void
test()
{
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, -2.5);
assert( !(lhs == rhs));
}
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, 2.5);
assert(lhs == rhs);
}
test_constexpr<T> ();
}
int main()
{
test<float>();
test<double>();
test<long double>();
// test_constexpr<int> ();
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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>
// bool
// operator==(const complex<T>& lhs, const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test_constexpr()
{
#if _LIBCPP_STD_VER > 11
{
constexpr std::complex<T> lhs(1.5, 2.5);
constexpr T rhs(-2.5);
static_assert(!(lhs == rhs), "");
}
{
constexpr std::complex<T> lhs(1.5, 0);
constexpr T rhs(-2.5);
static_assert(!(lhs == rhs), "");
}
{
constexpr std::complex<T> lhs(1.5, 2.5);
constexpr T rhs(1.5);
static_assert(!(lhs == rhs), "");
}
{
constexpr std::complex<T> lhs(1.5, 0);
constexpr T rhs(1.5);
static_assert( (lhs == rhs), "");
}
#endif
}
template <class T>
void
test()
{
{
std::complex<T> lhs(1.5, 2.5);
T rhs(-2.5);
assert(!(lhs == rhs));
}
{
std::complex<T> lhs(1.5, 0);
T rhs(-2.5);
assert(!(lhs == rhs));
}
{
std::complex<T> lhs(1.5, 2.5);
T rhs(1.5);
assert(!(lhs == rhs));
}
{
std::complex<T> lhs(1.5, 0);
T rhs(1.5);
assert( (lhs == rhs));
}
test_constexpr<T> ();
}
int main()
{
test<float>();
test<double>();
test<long double>();
// test_constexpr<int> ();
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator-(const complex<T>& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x)
{
assert(lhs - rhs == x);
}
template <class T>
void
test()
{
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(3.5, 4.5);
std::complex<T> x(-2.0, -2.0);
test(lhs, rhs, x);
}
{
std::complex<T> lhs(1.5, -2.5);
std::complex<T> rhs(-3.5, 4.5);
std::complex<T> x(5.0, -7.0);
test(lhs, rhs, x);
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator-(const complex<T>& lhs, const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const std::complex<T>& lhs, const T& rhs, std::complex<T> x)
{
assert(lhs - rhs == x);
}
template <class T>
void
test()
{
{
std::complex<T> lhs(1.5, 2.5);
T rhs(3.5);
std::complex<T> x(-2.0, 2.5);
test(lhs, rhs, x);
}
{
std::complex<T> lhs(1.5, -2.5);
T rhs(-3.5);
std::complex<T> x(5.0, -2.5);
test(lhs, rhs, x);
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,62 @@
//===----------------------------------------------------------------------===//
//
// 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>
// bool
// operator!=(const complex<T>& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test_constexpr()
{
#if _LIBCPP_STD_VER > 11
{
constexpr std::complex<T> lhs(1.5, 2.5);
constexpr std::complex<T> rhs(1.5, -2.5);
static_assert(lhs != rhs, "");
}
{
constexpr std::complex<T> lhs(1.5, 2.5);
constexpr std::complex<T> rhs(1.5, 2.5);
static_assert(!(lhs != rhs), "" );
}
#endif
}
template <class T>
void
test()
{
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, -2.5);
assert(lhs != rhs);
}
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, 2.5);
assert(!(lhs != rhs));
}
test_constexpr<T> ();
}
int main()
{
test<float>();
test<double>();
test<long double>();
// test_constexpr<int> ();
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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>
// bool
// operator!=(const complex<T>& lhs, const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test_constexpr()
{
#if _LIBCPP_STD_VER > 11
{
constexpr std::complex<T> lhs(1.5, 2.5);
constexpr T rhs(-2.5);
static_assert(lhs != rhs, "");
}
{
constexpr std::complex<T> lhs(1.5, 0);
constexpr T rhs(-2.5);
static_assert(lhs != rhs, "");
}
{
constexpr std::complex<T> lhs(1.5, 2.5);
constexpr T rhs(1.5);
static_assert(lhs != rhs, "");
}
{
constexpr std::complex<T> lhs(1.5, 0);
constexpr T rhs(1.5);
static_assert( !(lhs != rhs), "");
}
#endif
}
template <class T>
void
test()
{
{
std::complex<T> lhs(1.5, 2.5);
T rhs(-2.5);
assert(lhs != rhs);
}
{
std::complex<T> lhs(1.5, 0);
T rhs(-2.5);
assert(lhs != rhs);
}
{
std::complex<T> lhs(1.5, 2.5);
T rhs(1.5);
assert(lhs != rhs);
}
{
std::complex<T> lhs(1.5, 0);
T rhs(1.5);
assert( !(lhs != rhs));
}
test_constexpr<T> ();
}
int main()
{
test<float>();
test<double>();
test<long double>();
// test_constexpr<int> ();
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator+(const complex<T>& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x)
{
assert(lhs + rhs == x);
}
template <class T>
void
test()
{
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(3.5, 4.5);
std::complex<T> x(5.0, 7.0);
test(lhs, rhs, x);
}
{
std::complex<T> lhs(1.5, -2.5);
std::complex<T> rhs(-3.5, 4.5);
std::complex<T> x(-2.0, 2.0);
test(lhs, rhs, x);
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator+(const complex<T>& lhs, const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const std::complex<T>& lhs, const T& rhs, std::complex<T> x)
{
assert(lhs + rhs == x);
}
template <class T>
void
test()
{
{
std::complex<T> lhs(1.5, 2.5);
T rhs(3.5);
std::complex<T> x(5.0, 2.5);
test(lhs, rhs, x);
}
{
std::complex<T> lhs(1.5, -2.5);
T rhs(-3.5);
std::complex<T> x(-2.0, -2.5);
test(lhs, rhs, x);
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,161 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator*(const complex<T>& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& lhs, const std::complex<T>& rhs, std::complex<T> x)
{
assert(lhs * rhs == x);
}
template <class T>
void
test()
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, 2.5);
std::complex<T> x(-4.0, 7.5);
test(lhs, rhs, x);
}
// test edges
void test_edges()
{
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
for (unsigned j = 0; j < N; ++j)
{
std::complex<double> r = x[i] * x[j];
switch (classify(x[i]))
{
case zero:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == zero);
break;
case non_zero:
assert(classify(r) == zero);
break;
case inf:
assert(classify(r) == NaN);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
case non_zero:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == zero);
break;
case non_zero:
assert(classify(r) == non_zero);
break;
case inf:
assert(classify(r) == inf);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
case inf:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == NaN);
break;
case non_zero:
assert(classify(r) == inf);
break;
case inf:
assert(classify(r) == inf);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == inf);
break;
}
break;
case NaN:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == NaN);
break;
case non_zero:
assert(classify(r) == NaN);
break;
case inf:
assert(classify(r) == NaN);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
case non_zero_nan:
switch (classify(x[j]))
{
case zero:
assert(classify(r) == NaN);
break;
case non_zero:
assert(classify(r) == NaN);
break;
case inf:
assert(classify(r) == inf);
break;
case NaN:
assert(classify(r) == NaN);
break;
case non_zero_nan:
assert(classify(r) == NaN);
break;
}
break;
}
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -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>
// operator*(const complex<T>& lhs, const T& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const std::complex<T>& lhs, const T& rhs, std::complex<T> x)
{
assert(lhs * rhs == x);
}
template <class T>
void
test()
{
std::complex<T> lhs(1.5, 2.5);
T rhs(1.5);
std::complex<T> x(2.25, 3.75);
test(lhs, rhs, x);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -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>
// operator/(const T& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const T& lhs, const std::complex<T>& rhs, std::complex<T> x)
{
assert(lhs / rhs == x);
}
template <class T>
void
test()
{
T lhs(-8.5);
std::complex<T> rhs(1.5, 2.5);
std::complex<T> x(-1.5, 2.5);
test(lhs, rhs, x);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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>
// bool
// operator==(const T& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test_constexpr()
{
#if _LIBCPP_STD_VER > 11
{
constexpr T lhs(-2.5);
constexpr std::complex<T> rhs(1.5, 2.5);
static_assert(!(lhs == rhs), "");
}
{
constexpr T lhs(-2.5);
constexpr std::complex<T> rhs(1.5, 0);
static_assert(!(lhs == rhs), "");
}
{
constexpr T lhs(1.5);
constexpr std::complex<T> rhs(1.5, 2.5);
static_assert(!(lhs == rhs), "");
}
{
constexpr T lhs(1.5);
constexpr std::complex<T> rhs(1.5, 0);
static_assert(lhs == rhs, "");
}
#endif
}
template <class T>
void
test()
{
{
T lhs(-2.5);
std::complex<T> rhs(1.5, 2.5);
assert(!(lhs == rhs));
}
{
T lhs(-2.5);
std::complex<T> rhs(1.5, 0);
assert(!(lhs == rhs));
}
{
T lhs(1.5);
std::complex<T> rhs(1.5, 2.5);
assert(!(lhs == rhs));
}
{
T lhs(1.5);
std::complex<T> rhs(1.5, 0);
assert(lhs == rhs);
}
test_constexpr<T> ();
}
int main()
{
test<float>();
test<double>();
test<long double>();
// test_constexpr<int>();
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator-(const T& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const T& lhs, const std::complex<T>& rhs, std::complex<T> x)
{
assert(lhs - rhs == x);
}
template <class T>
void
test()
{
{
T lhs(1.5);
std::complex<T> rhs(3.5, 4.5);
std::complex<T> x(-2.0, -4.5);
test(lhs, rhs, x);
}
{
T lhs(1.5);
std::complex<T> rhs(-3.5, 4.5);
std::complex<T> x(5.0, -4.5);
test(lhs, rhs, x);
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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>
// bool
// operator!=(const T& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test_constexpr()
{
#if _LIBCPP_STD_VER > 11
{
constexpr T lhs(-2.5);
constexpr std::complex<T> rhs(1.5, 2.5);
static_assert (lhs != rhs, "");
}
{
constexpr T lhs(-2.5);
constexpr std::complex<T> rhs(1.5, 0);
static_assert (lhs != rhs, "");
}
{
constexpr T lhs(1.5);
constexpr std::complex<T> rhs(1.5, 2.5);
static_assert (lhs != rhs, "");
}
{
constexpr T lhs(1.5);
constexpr std::complex<T> rhs(1.5, 0);
static_assert (!(lhs != rhs), "");
}
#endif
}
template <class T>
void
test()
{
{
T lhs(-2.5);
std::complex<T> rhs(1.5, 2.5);
assert (lhs != rhs);
}
{
T lhs(-2.5);
std::complex<T> rhs(1.5, 0);
assert (lhs != rhs);
}
{
T lhs(1.5);
std::complex<T> rhs(1.5, 2.5);
assert (lhs != rhs);
}
{
T lhs(1.5);
std::complex<T> rhs(1.5, 0);
assert (!(lhs != rhs));
}
test_constexpr<T> ();
}
int main()
{
test<float>();
test<double>();
test<long double>();
// test_constexpr<int>();
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator+(const T& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const T& lhs, const std::complex<T>& rhs, std::complex<T> x)
{
assert(lhs + rhs == x);
}
template <class T>
void
test()
{
{
T lhs(1.5);
std::complex<T> rhs(3.5, 4.5);
std::complex<T> x(5.0, 4.5);
test(lhs, rhs, x);
}
{
T lhs(1.5);
std::complex<T> rhs(-3.5, 4.5);
std::complex<T> x(-2.0, 4.5);
test(lhs, rhs, x);
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -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>
// operator*(const T& lhs, const complex<T>& rhs);
#include <complex>
#include <cassert>
template <class T>
void
test(const T& lhs, const std::complex<T>& rhs, std::complex<T> x)
{
assert(lhs * rhs == x);
}
template <class T>
void
test()
{
T lhs(1.5);
std::complex<T> rhs(1.5, 2.5);
std::complex<T> x(2.25, 3.75);
test(lhs, rhs, x);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,99 @@
//===----------------------------------------------------------------------===//
//
// 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, class charT, class traits>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is, complex<T>& x);
#include <complex>
#include <sstream>
#include <cassert>
int main()
{
{
std::istringstream is("5");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(5, 0));
assert(is.eof());
}
{
std::istringstream is(" 5 ");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(5, 0));
assert(is.good());
}
{
std::istringstream is(" 5, ");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(5, 0));
assert(is.good());
}
{
std::istringstream is(" , 5, ");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(0, 0));
assert(is.fail());
}
{
std::istringstream is("5.5 ");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(5.5, 0));
assert(is.good());
}
{
std::istringstream is(" ( 5.5 ) ");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(5.5, 0));
assert(is.good());
}
{
std::istringstream is(" 5.5)");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(5.5, 0));
assert(is.good());
}
{
std::istringstream is("(5.5 ");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(0, 0));
assert(is.fail());
}
{
std::istringstream is("(5.5,");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(0, 0));
assert(is.fail());
}
{
std::istringstream is("( -5.5 , -6.5 )");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(-5.5, -6.5));
assert(!is.eof());
}
{
std::istringstream is("(-5.5,-6.5)");
std::complex<double> c;
is >> c;
assert(c == std::complex<double>(-5.5, -6.5));
assert(!is.eof());
}
}

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// 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, class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
#include <complex>
#include <sstream>
#include <cassert>
int main()
{
std::complex<double> c(1, 2);
std::ostringstream os;
os << c;
assert(os.str() == "(1,2)");
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator-(const complex<T>& lhs);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> z(1.5, 2.5);
assert(z.real() == 1.5);
assert(z.imag() == 2.5);
std::complex<T> c = -z;
assert(c.real() == -1.5);
assert(c.imag() == -2.5);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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>
// operator+(const complex<T>&);
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> z(1.5, 2.5);
assert(z.real() == 1.5);
assert(z.imag() == 2.5);
std::complex<T> c = +z;
assert(c.real() == 1.5);
assert(c.imag() == 2.5);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<double>
// {
// public:
// constexpr complex(const complex<float>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<float> cd(2.5, 3.5);
std::complex<double> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<float> cd(2.5, 3.5);
constexpr std::complex<double> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<double>
// {
// public:
// constexpr complex(const complex<float>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<float> cd(2.5, 3.5);
std::complex<double> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<float> cd(2.5, 3.5);
constexpr std::complex<double> cf = cd;
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<double>
// {
// public:
// explicit constexpr complex(const complex<long double>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<long double> cd(2.5, 3.5);
std::complex<double> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<long double> cd(2.5, 3.5);
constexpr std::complex<double> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<double>
// {
// public:
// explicit constexpr complex(const complex<long double>&);
// };
#include <complex>
#include <cassert>
int main()
{
const std::complex<long double> cd(2.5, 3.5);
std::complex<double> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<float>
// {
// public:
// explicit constexpr complex(const complex<double>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<double> cd(2.5, 3.5);
std::complex<float> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<double> cd(2.5, 3.5);
constexpr std::complex<float> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<float>
// {
// public:
// explicit constexpr complex(const complex<double>&);
// };
#include <complex>
#include <cassert>
int main()
{
const std::complex<double> cd(2.5, 3.5);
std::complex<float> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<float>
// {
// public:
// explicit constexpr complex(const complex<long double>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<long double> cd(2.5, 3.5);
std::complex<float> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<long double> cd(2.5, 3.5);
constexpr std::complex<float> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<float>
// {
// public:
// explicit constexpr complex(const complex<long double>&);
// };
#include <complex>
#include <cassert>
int main()
{
const std::complex<long double> cd(2.5, 3.5);
std::complex<float> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<long double>
// {
// public:
// constexpr complex(const complex<double>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<double> cd(2.5, 3.5);
std::complex<long double> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<double> cd(2.5, 3.5);
constexpr std::complex<long double> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<long double>
// {
// public:
// constexpr complex(const complex<double>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<double> cd(2.5, 3.5);
std::complex<long double> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<double> cd(2.5, 3.5);
constexpr std::complex<long double> cf = cd;
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<long double>
// {
// public:
// constexpr complex(const complex<float>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<float> cd(2.5, 3.5);
std::complex<long double> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<float> cd(2.5, 3.5);
constexpr std::complex<long double> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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 complex<long double>
// {
// public:
// constexpr complex(const complex<float>&);
// };
#include <complex>
#include <cassert>
int main()
{
{
const std::complex<float> cd(2.5, 3.5);
std::complex<long double> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<float> cd(2.5, 3.5);
constexpr std::complex<long double> cf = cd;
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,140 @@
//===----------------------------------------------------------------------===//
//
// 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>
// acos(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(acos(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(INFINITY, 1), std::complex<T>(0, -INFINITY));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = acos(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
is_about(r.real(), pi/2);
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) != std::signbit(r.imag()));
}
else if (x[i].real() == 0 && std::isnan(x[i].imag()))
{
is_about(r.real(), pi/2);
assert(std::isnan(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
is_about(r.real(), pi/2);
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) != std::signbit(r.imag()));
}
else if (std::isfinite(x[i].real()) && x[i].real() != 0 && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isfinite(x[i].imag()))
{
is_about(r.real(), pi);
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) != std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isfinite(x[i].imag()))
{
assert(r.real() == 0);
assert(!std::signbit(r.real()));
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) != std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isinf(x[i].imag()))
{
is_about(r.real(), 0.75 * pi);
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) != std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isinf(x[i].imag()))
{
is_about(r.real(), 0.25 * pi);
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) != std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isinf(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) != std::signbit(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (!std::signbit(x[i].real()) && !std::signbit(x[i].imag()))
{
assert(!std::signbit(r.real()));
assert( std::signbit(r.imag()));
}
else if (std::signbit(x[i].real()) && !std::signbit(x[i].imag()))
{
assert(!std::signbit(r.real()));
assert( std::signbit(r.imag()));
}
else if (std::signbit(x[i].real()) && std::signbit(x[i].imag()))
{
assert(!std::signbit(r.real()));
assert(!std::signbit(r.imag()));
}
else if (!std::signbit(x[i].real()) && std::signbit(x[i].imag()))
{
assert(!std::signbit(r.real()));
assert(!std::signbit(r.imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,142 @@
//===----------------------------------------------------------------------===//
//
// 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>
// acosh(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(acosh(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(INFINITY, 1), std::complex<T>(INFINITY, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = acosh(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(!std::signbit(r.real()));
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi/2);
else
is_about(r.imag(), pi/2);
}
else if (x[i].real() == 1 && x[i].imag() == 0)
{
assert(r.real() == 0);
assert(!std::signbit(r.real()));
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi/2);
else
is_about(r.imag(), pi/2);
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isfinite(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi);
else
is_about(r.imag(), pi);
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isfinite(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
if (std::signbit(x[i].imag()))
is_about(r.imag(), -0.75 * pi);
else
is_about(r.imag(), 0.75 * pi);
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
if (std::signbit(x[i].imag()))
is_about(r.imag(), -0.25 * pi);
else
is_about(r.imag(), 0.25 * pi);
}
else if (std::isinf(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else
{
assert(!std::signbit(r.real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,120 @@
//===----------------------------------------------------------------------===//
//
// 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>
// asin(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(asin(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(0, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = asin(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(r.real() == 0);
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if ( x[i].real() == 0 && std::isnan(x[i].imag()))
{
assert(r.real() == 0);
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag()))
{
if (x[i].real() > 0)
is_about(r.real(), pi/2);
else
is_about(r.real(), - pi/2);
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isinf(x[i].imag()))
{
if (std::signbit(x[i].real()))
is_about(r.real(), -pi/4);
else
is_about(r.real(), pi/4);
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].real()) != std::signbit(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isinf(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else
{
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,119 @@
//===----------------------------------------------------------------------===//
//
// 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>
// asinh(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(asinh(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(0, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = asinh(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi/2);
else
is_about(r.imag(), pi/2);
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi/4);
else
is_about(r.imag(), pi/4);
}
else if (std::isinf(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && x[i].imag() == 0)
{
assert(std::isnan(r.real()));
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else
{
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// 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>
// atan(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(atan(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(0, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = atan(x[i]);
std::complex<double> t1(-imag(x[i]), real(x[i]));
std::complex<double> t2 = atanh(t1);
std::complex<double> z(imag(t2), -real(t2));
if (std::isnan(real(r)))
assert(std::isnan(real(z)));
else
{
assert(real(r) == real(z));
assert(std::signbit(real(r)) == std::signbit(real(z)));
}
if (std::isnan(imag(r)))
assert(std::isnan(imag(z)));
else
{
assert(imag(r) == imag(z));
assert(std::signbit(imag(r)) == std::signbit(imag(z)));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,132 @@
//===----------------------------------------------------------------------===//
//
// 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>
// atanh(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(atanh(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(0, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = atanh(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if ( x[i].real() == 0 && std::isnan(x[i].imag()))
{
assert(r.real() == 0);
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::abs(x[i].real()) == 1 && x[i].imag() == 0)
{
assert(std::isinf(r.real()));
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(r.real() == 0);
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
if (x[i].imag() > 0)
is_about(r.imag(), pi/2);
else
is_about(r.imag(), -pi/2);
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(r.real() == 0);
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi/2);
else
is_about(r.imag(), pi/2);
}
else if (std::isinf(x[i].real()) && std::isinf(x[i].imag()))
{
assert(r.real() == 0);
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi/2);
else
is_about(r.imag(), pi/2);
}
else if (std::isinf(x[i].real()) && std::isnan(x[i].imag()))
{
assert(r.real() == 0);
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isinf(x[i].imag()))
{
assert(r.real() == 0);
assert(std::signbit(x[i].real()) == std::signbit(r.real()));
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi/2);
else
is_about(r.imag(), pi/2);
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else
{
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// 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>
// cos(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(cos(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(1, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = cos(x[i]);
std::complex<double> t1(-imag(x[i]), real(x[i]));
std::complex<double> z = cosh(t1);
if (std::isnan(real(r)))
assert(std::isnan(real(z)));
else
{
assert(real(r) == real(z));
assert(std::signbit(real(r)) == std::signbit(real(z)));
}
if (std::isnan(imag(r)))
assert(std::isnan(imag(z)));
else
{
assert(imag(r) == imag(z));
assert(std::signbit(imag(r)) == std::signbit(imag(z)));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,118 @@
//===----------------------------------------------------------------------===//
//
// 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>
// cosh(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(cosh(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(1, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = cosh(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(r.real() == 1);
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (x[i].real() == 0 && std::isinf(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(r.imag() == 0);
}
else if (x[i].real() == 0 && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(r.imag() == 0);
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].imag() == 0)
{
assert(std::isinf(r.real()));
assert(!std::signbit(r.real()));
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::signbit(r.real()) == std::signbit(cos(x[i].imag())));
assert(std::isinf(r.imag()));
assert(std::signbit(r.imag()) == std::signbit(x[i].real() * sin(x[i].imag())));
}
else if (std::isinf(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && x[i].imag() == 0)
{
assert(std::isnan(r.real()));
assert(r.imag() == 0);
}
else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,114 @@
//===----------------------------------------------------------------------===//
//
// 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>
// exp(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(exp(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(1, 0));
}
void test_edges()
{
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = exp(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(r.real() == 1.0);
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && x[i].imag() == 0)
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isinf(x[i].imag()))
{
assert(r.real() == 0);
assert(r.imag() == 0);
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isnan(x[i].imag()))
{
assert(r.real() == 0);
assert(r.imag() == 0);
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isnan(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && x[i].imag() == 0)
{
assert(std::isnan(r.real()));
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isnan(x[i].real()) && x[i].imag() != 0)
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isfinite(x[i].imag()) && std::abs(x[i].imag()) <= 1)
{
assert(!std::signbit(r.real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,131 @@
//===----------------------------------------------------------------------===//
//
// 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>
// log(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(log(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(-INFINITY, 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)
{
std::complex<double> r = log(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
if (std::signbit(x[i].real()))
{
assert(std::isinf(r.real()));
assert(r.real() < 0);
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi);
else
is_about(r.imag(), pi);
}
else
{
assert(std::isinf(r.real()));
assert(r.real() < 0);
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
if (x[i].imag() > 0)
is_about(r.imag(), pi/2);
else
is_about(r.imag(), -pi/2);
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isfinite(x[i].imag()))
{
assert(std::isinf(r.real()) && r.real() > 0);
if (r.imag() > 0)
is_about(r.imag(), pi);
else
is_about(r.imag(), -pi);
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isfinite(x[i].imag()))
{
assert(std::isinf(r.real()) && r.real() > 0);
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (x[i].real() == 1 && x[i].imag() == 0)
{
assert(r.real() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (x[i].real() == 0 && x[i].imag() == 1)
{
assert(r.real() == 0);
is_about(r.imag(), pi/2);
}
else if (x[i].real() == -1 && x[i].imag() == 0)
{
assert(r.real() == 0);
if (std::signbit(x[i].imag()))
is_about(r.imag(), -pi);
else
is_about(r.imag(), pi);
}
else if (x[i].real() == 0 && x[i].imag() == -1)
{
assert(r.real() == 0);
is_about(r.imag(), -pi/2);
}
else if (std::isfinite(x[i].real()) && std::isfinite(x[i].imag()) && abs(x[i]) < 1)
{
assert( std::signbit(r.real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isfinite(x[i].real()) && std::isfinite(x[i].imag()) && abs(x[i]) > 1)
{
assert(!std::signbit(r.real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// 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>
// log10(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(log10(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(-INFINITY, 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)
{
std::complex<double> r = log10(x[i]);
std::complex<double> z = log(x[i])/std::log(10);
if (std::isnan(real(r)))
assert(std::isnan(real(z)));
else
{
assert(real(r) == real(z));
assert(std::signbit(real(r)) == std::signbit(real(z)));
}
if (std::isnan(imag(r)))
assert(std::isnan(imag(z)));
else
{
assert(imag(r) == imag(z));
assert(std::signbit(imag(r)) == std::signbit(imag(z)));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -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>
// pow(const complex<T>& x, const complex<T>& y);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& a, const std::complex<T>& b, std::complex<T> x)
{
std::complex<T> c = pow(a, b);
is_about(real(c), real(x));
is_about(imag(c), imag(x));
}
template <class T>
void
test()
{
test(std::complex<T>(2, 3), std::complex<T>(2, 0), std::complex<T>(-5, 12));
}
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)
{
for (unsigned j = 0; j < N; ++j)
{
std::complex<double> r = pow(x[i], x[j]);
std::complex<double> z = exp(x[j] * log(x[i]));
if (std::isnan(real(r)))
assert(std::isnan(real(z)));
else
{
assert(real(r) == real(z));
assert(std::signbit(real(r)) == std::signbit(real(z)));
}
if (std::isnan(imag(r)))
assert(std::isnan(imag(z)));
else
{
assert(imag(r) == imag(z));
assert(std::signbit(imag(r)) == std::signbit(imag(z)));
}
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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>
// pow(const complex<T>& x, const T& y);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& a, const T& b, std::complex<T> x)
{
std::complex<T> c = pow(a, b);
is_about(real(c), real(x));
is_about(imag(c), imag(x));
}
template <class T>
void
test()
{
test(std::complex<T>(2, 3), T(2), std::complex<T>(-5, 12));
}
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)
{
for (unsigned j = 0; j < N; ++j)
{
std::complex<double> r = pow(x[i], real(x[j]));
std::complex<double> z = exp(std::complex<double>(real(x[j])) * log(x[i]));
if (std::isnan(real(r)))
assert(std::isnan(real(z)));
else
{
assert(real(r) == real(z));
}
if (std::isnan(imag(r)))
assert(std::isnan(imag(z)));
else
{
assert(imag(r) == imag(z));
}
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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>
// pow(const T& x, const complex<T>& y);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const T& a, const std::complex<T>& b, std::complex<T> x)
{
std::complex<T> c = pow(a, b);
is_about(real(c), real(x));
assert(std::abs(imag(c)) < 1.e-6);
}
template <class T>
void
test()
{
test(T(2), std::complex<T>(2), std::complex<T>(4));
}
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)
{
for (unsigned j = 0; j < N; ++j)
{
std::complex<double> r = pow(real(x[i]), x[j]);
std::complex<double> z = exp(x[j] * log(std::complex<double>(real(x[i]))));
if (std::isnan(real(r)))
assert(std::isnan(real(z)));
else
{
assert(real(r) == real(z));
}
if (std::isnan(imag(r)))
assert(std::isnan(imag(z)));
else
{
assert(imag(r) == imag(z));
}
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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>
// sin(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(sin(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(0, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = sin(x[i]);
std::complex<double> t1(-imag(x[i]), real(x[i]));
std::complex<double> t2 = sinh(t1);
std::complex<double> z(imag(t2), -real(t2));
if (std::isnan(real(r)))
assert(std::isnan(real(z)));
else
{
assert(real(r) == real(z));
assert(std::signbit(real(r)) == std::signbit(real(z)));
}
if (std::isnan(imag(r)))
assert(std::isnan(imag(z)));
else
{
assert(imag(r) == imag(z));
assert(std::signbit(imag(r)) == std::signbit(imag(z)));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,119 @@
//===----------------------------------------------------------------------===//
//
// 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>
// sinh(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(sinh(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(0, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = sinh(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(r.real() == 0);
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (x[i].real() == 0 && std::isinf(x[i].imag()))
{
assert(r.real() == 0);
assert(std::isnan(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (x[i].real() == 0 && std::isnan(x[i].imag()))
{
assert(r.real() == 0);
assert(std::isnan(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].imag() == 0)
{
assert(std::isinf(r.real()));
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::signbit(r.real()) == std::signbit(x[i].real() * cos(x[i].imag())));
assert(std::isinf(r.imag()));
assert(std::signbit(r.imag()) == std::signbit(sin(x[i].imag())));
}
else if (std::isinf(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && x[i].imag() == 0)
{
assert(std::isnan(r.real()));
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,109 @@
//===----------------------------------------------------------------------===//
//
// 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>
// sqrt(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
std::complex<T> a = sqrt(c);
is_about(real(a), real(x));
assert(std::abs(imag(c)) < 1.e-6);
}
template <class T>
void
test()
{
test(std::complex<T>(64, 0), std::complex<T>(8, 0));
}
void test_edges()
{
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = sqrt(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(!std::signbit(r.real()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isinf(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
assert(std::isinf(r.imag()));
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isfinite(x[i].imag()))
{
assert(r.real() == 0);
assert(!std::signbit(r.real()));
assert(std::isinf(r.imag()));
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isfinite(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
assert(r.imag() == 0);
assert(std::signbit(x[i].imag()) == std::signbit(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() < 0 && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isinf(r.imag()));
}
else if (std::isinf(x[i].real()) && x[i].real() > 0 && std::isnan(x[i].imag()))
{
assert(std::isinf(r.real()));
assert(r.real() > 0);
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && (std::isfinite(x[i].imag()) || std::isnan(x[i].imag())))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::signbit(x[i].imag()))
{
assert(!std::signbit(r.real()));
assert(std::signbit(r.imag()));
}
else
{
assert(!std::signbit(r.real()));
assert(!std::signbit(r.imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// 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>
// tan(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(tan(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(0, 0));
test(std::complex<T>(10000, -10000), std::complex<T>(0, -1));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = tan(x[i]);
std::complex<double> t1(-imag(x[i]), real(x[i]));
std::complex<double> t2 = tanh(t1);
std::complex<double> z(imag(t2), -real(t2));
if (std::isnan(real(r)))
assert(std::isnan(real(z)));
else
{
assert(real(r) == real(z));
assert(std::signbit(real(r)) == std::signbit(real(z)));
}
if (std::isnan(imag(r)))
assert(std::isnan(imag(z)));
else
{
assert(imag(r) == imag(z));
assert(std::signbit(imag(r)) == std::signbit(imag(z)));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -0,0 +1,101 @@
//===----------------------------------------------------------------------===//
//
// 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>
// tanh(const complex<T>& x);
#include <complex>
#include <cassert>
#include "../cases.h"
template <class T>
void
test(const std::complex<T>& c, std::complex<T> x)
{
assert(tanh(c) == x);
}
template <class T>
void
test()
{
test(std::complex<T>(0, 0), std::complex<T>(0, 0));
}
void test_edges()
{
typedef std::complex<double> C;
const double pi = std::atan2(+0., -0.);
const unsigned N = sizeof(x) / sizeof(x[0]);
for (unsigned i = 0; i < N; ++i)
{
std::complex<double> r = tanh(x[i]);
if (x[i].real() == 0 && x[i].imag() == 0)
{
assert(r.real() == 0);
assert(std::signbit(r.real()) == std::signbit(x[i].real()));
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isfinite(x[i].real()) && std::isinf(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isfinite(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isinf(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(r.real() == 1);
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(sin(2*x[i].imag())));
}
else if (std::isinf(x[i].real()) && std::isinf(x[i].imag()))
{
assert(r.real() == 1);
assert(r.imag() == 0);
}
else if (std::isinf(x[i].real()) && std::isnan(x[i].imag()))
{
assert(r.real() == 1);
assert(r.imag() == 0);
}
else if (std::isnan(x[i].real()) && x[i].imag() == 0)
{
assert(std::isnan(r.real()));
assert(r.imag() == 0);
assert(std::signbit(r.imag()) == std::signbit(x[i].imag()));
}
else if (std::isnan(x[i].real()) && std::isfinite(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
else if (std::isnan(x[i].real()) && std::isnan(x[i].imag()))
{
assert(std::isnan(r.real()));
assert(std::isnan(r.imag()));
}
}
}
int main()
{
test<float>();
test<double>();
test<long double>();
test_edges();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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>();
}

View File

@@ -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>();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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>();
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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>
// class complex
// {
// public:
// typedef T value_type;
// ...
// };
#include <complex>
#include <type_traits>
template <class T>
void
test()
{
typedef std::complex<T> C;
static_assert((std::is_same<typename C::value_type, T>::value), "");
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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>
#include <complex>
#include <cassert>
template <class T>
void
test()
{
std::complex<T> z;
T* a = (T*)&z;
assert(0 == z.real());
assert(0 == z.imag());
assert(a[0] == z.real());
assert(a[1] == z.imag());
a[0] = 5;
a[1] = 6;
assert(a[0] == z.real());
assert(a[1] == z.imag());
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

View File

@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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>
#include <complex>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
int main()
{
}

Some files were not shown because too many files have changed in this diff Show More