xref: /minix3/external/bsd/libc++/dist/libcxx/test/numerics/complex.number/cmplx.over/arg.pass.cpp (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc 
10*4684ddb6SLionel Sambuc // <complex>
11*4684ddb6SLionel Sambuc 
12*4684ddb6SLionel Sambuc // template<Arithmetic T>
13*4684ddb6SLionel Sambuc //   T
14*4684ddb6SLionel Sambuc //   arg(T x);
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc #include <complex>
17*4684ddb6SLionel Sambuc #include <type_traits>
18*4684ddb6SLionel Sambuc #include <cassert>
19*4684ddb6SLionel Sambuc 
20*4684ddb6SLionel Sambuc #include "../cases.h"
21*4684ddb6SLionel Sambuc 
22*4684ddb6SLionel Sambuc template <class T>
23*4684ddb6SLionel Sambuc void
test(T x,typename std::enable_if<std::is_integral<T>::value>::type * =0)24*4684ddb6SLionel Sambuc test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
25*4684ddb6SLionel Sambuc {
26*4684ddb6SLionel Sambuc     static_assert((std::is_same<decltype(std::arg(x)), double>::value), "");
27*4684ddb6SLionel Sambuc     assert(std::arg(x) == arg(std::complex<double>(x, 0)));
28*4684ddb6SLionel Sambuc }
29*4684ddb6SLionel Sambuc 
30*4684ddb6SLionel Sambuc template <class T>
31*4684ddb6SLionel Sambuc void
test(T x,typename std::enable_if<!std::is_integral<T>::value>::type * =0)32*4684ddb6SLionel Sambuc test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
33*4684ddb6SLionel Sambuc {
34*4684ddb6SLionel Sambuc     static_assert((std::is_same<decltype(std::arg(x)), T>::value), "");
35*4684ddb6SLionel Sambuc     assert(std::arg(x) == arg(std::complex<T>(x, 0)));
36*4684ddb6SLionel Sambuc }
37*4684ddb6SLionel Sambuc 
38*4684ddb6SLionel Sambuc template <class T>
39*4684ddb6SLionel Sambuc void
test()40*4684ddb6SLionel Sambuc test()
41*4684ddb6SLionel Sambuc {
42*4684ddb6SLionel Sambuc     test<T>(0);
43*4684ddb6SLionel Sambuc     test<T>(1);
44*4684ddb6SLionel Sambuc     test<T>(10);
45*4684ddb6SLionel Sambuc }
46*4684ddb6SLionel Sambuc 
main()47*4684ddb6SLionel Sambuc int main()
48*4684ddb6SLionel Sambuc {
49*4684ddb6SLionel Sambuc     test<float>();
50*4684ddb6SLionel Sambuc     test<double>();
51*4684ddb6SLionel Sambuc     test<long double>();
52*4684ddb6SLionel Sambuc     test<int>();
53*4684ddb6SLionel Sambuc     test<unsigned>();
54*4684ddb6SLionel Sambuc     test<long long>();
55*4684ddb6SLionel Sambuc }
56