1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <complex> 11 12 // void real(T val); 13 // void imag(T val); 14 15 #include <complex> 16 #include <cassert> 17 18 template <class T> 19 void test_constexpr()20test_constexpr() 21 { 22 #if _LIBCPP_STD_VER > 11 23 constexpr std::complex<T> c1; 24 static_assert(c1.real() == 0, ""); 25 static_assert(c1.imag() == 0, ""); 26 constexpr std::complex<T> c2(3); 27 static_assert(c2.real() == 3, ""); 28 static_assert(c2.imag() == 0, ""); 29 constexpr std::complex<T> c3(3, 4); 30 static_assert(c3.real() == 3, ""); 31 static_assert(c3.imag() == 4, ""); 32 #endif 33 } 34 35 template <class T> 36 void test()37test() 38 { 39 std::complex<T> c; 40 assert(c.real() == 0); 41 assert(c.imag() == 0); 42 c.real(3.5); 43 assert(c.real() == 3.5); 44 assert(c.imag() == 0); 45 c.imag(4.5); 46 assert(c.real() == 3.5); 47 assert(c.imag() == 4.5); 48 c.real(-4.5); 49 assert(c.real() == -4.5); 50 assert(c.imag() == 4.5); 51 c.imag(-5.5); 52 assert(c.real() == -4.5); 53 assert(c.imag() == -5.5); 54 55 test_constexpr<T> (); 56 } 57 main()58int main() 59 { 60 test<float>(); 61 test<double>(); 62 test<long double>(); 63 test_constexpr<int> (); 64 } 65