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 // constexpr complex(const T& re = T(), const T& im = T()); 13 14 #include <complex> 15 #include <cassert> 16 17 template <class T> 18 void 19 test() 20 { 21 { 22 const std::complex<T> c; 23 assert(c.real() == 0); 24 assert(c.imag() == 0); 25 } 26 { 27 const std::complex<T> c = 7.5; 28 assert(c.real() == 7.5); 29 assert(c.imag() == 0); 30 } 31 { 32 const std::complex<T> c(8.5); 33 assert(c.real() == 8.5); 34 assert(c.imag() == 0); 35 } 36 { 37 const std::complex<T> c(10.5, -9.5); 38 assert(c.real() == 10.5); 39 assert(c.imag() == -9.5); 40 } 41 #ifndef _LIBCPP_HAS_NO_CONSTEXPR 42 { 43 constexpr std::complex<T> c; 44 static_assert(c.real() == 0, ""); 45 static_assert(c.imag() == 0, ""); 46 } 47 { 48 constexpr std::complex<T> c = 7.5; 49 static_assert(c.real() == 7.5, ""); 50 static_assert(c.imag() == 0, ""); 51 } 52 { 53 constexpr std::complex<T> c(8.5); 54 static_assert(c.real() == 8.5, ""); 55 static_assert(c.imag() == 0, ""); 56 } 57 { 58 constexpr std::complex<T> c(10.5, -9.5); 59 static_assert(c.real() == 10.5, ""); 60 static_assert(c.imag() == -9.5, ""); 61 } 62 #endif 63 } 64 65 int main() 66 { 67 test<float>(); 68 test<double>(); 69 test<long double>(); 70 } 71