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 // complex& operator+=(const complex& rhs); 13 14 #include <complex> 15 #include <cassert> 16 17 template <class T> 18 void test()19test() 20 { 21 std::complex<T> c; 22 const std::complex<T> c2(1.5, 2.5); 23 assert(c.real() == 0); 24 assert(c.imag() == 0); 25 c += c2; 26 assert(c.real() == 1.5); 27 assert(c.imag() == 2.5); 28 c += c2; 29 assert(c.real() == 3); 30 assert(c.imag() == 5); 31 32 std::complex<T> c3; 33 34 c3 = c; 35 std::complex<int> ic (1,1); 36 c3 += ic; 37 assert(c3.real() == 4); 38 assert(c3.imag() == 6); 39 40 c3 = c; 41 std::complex<float> fc (1,1); 42 c3 += fc; 43 assert(c3.real() == 4); 44 assert(c3.imag() == 6); 45 } 46 main()47int main() 48 { 49 test<float>(); 50 test<double>(); 51 test<long double>(); 52 } 53