Complex number arithmetic
nisse at lysator.liu.se
Fri May 4 13:25:46 CEST 2007
"Vegard Nossum" <vegard at peltkore.net> writes:
> I've introduced a new type, the mpc_t, which contains two rational numbers
> for the real and imaginary parts.
I've had a quick look at the header file, and the interface seems sane
(except that mpc_t is a bad name).
I think you should add
* a function to get the square absolute value,
* a comparison function comparing the absolute value of too complex
rational, and maybe also for comparing the absolute value of a
complex rational to a real rational number (maybe with a pre-squared
* a squaring function
I can't say if it makes sense to add something like this to gmp, but
prerequisites for doing that would be good testcases for all
functions, and documentation.
Ah, and in mpc_mul, I suspect you can do this more efficiently than
with four calls to mpq_mul. Maybe the standard way of doing complex
multiplication using three real multiplications is not the best way
either (since addition and subtraction of rationals implies
multiplication). One would have to think carefully about the
decomposition into numerator and denominator to sort it out. And test
cases are crucial before starting on serious optimization.
More information about the gmp-devel