I recently got sorta addicted to complex numbers. I created a struct that stores the real and imaginary parts in two separate variables. I made some functions that can take those inputs and outputs the actual answer. Except factorial(). How do i calculate it? Here’s an example on one of the functions I made:
Cmplx pow(Cmplx base, Cmplx exponent)
{
double radius = pow(pow(base.real, 2) + pow(base.imag, 2), exponent.real / 2) * pow(M_E, -exponent.imag * atan2(base.imag, base.real));
double theta = exponent.real * atan2(base.imag, base.real) + 0.5 * exponent.imag * log(pow(base.real, 2) + pow(base.imag, 2));
return {radius * cos(theta), radius * sin(theta)};
}
I can use the gamma function but I don’t know how to extend it to a struct. I tried to calculate it using powers but it required log((a+bi)!)
which is what I’m trying to avoid so I gave up.
egg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.