I'm running the following code:
complex<int16_t> num1 (953, -20068);
complex<int16_t> num2 (953, -20068);
complex<int32_t> result;
result = num1*num2;
std::cout << to_string(result.real()) << "+" << to_string(result.imag()) << "i"<< std::endl;
I get the following result:
-15199+23416i
But if I calculate the multiplication according to the formula of multiplication of complex numbers:
complex<int16_t> num1 (953, -20068);
complex<int16_t> num2 (953, -20068);
int32_t A = ((num1.real())*(num2.real()))-((num1.imag())*(num2.imag()));
int32_t B = ((num1.real())*(num2.imag()))+((num2.real())*(num1.imag()));
std::cout << to_string(A) << to_string(B) << "i"<< std::endl;
I get the following result:
-401816415-38249608i
My question is why the formula of multiplying complex numbers returns a different result from that of the oprator* (of the type std::complex)?