Karim Belabas on Sat, 10 Mar 2007 19:14:00 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Desired behaviour ? |
* Loic Grenie [2007-03-10 17:41]: > I'm just wondering if there is a strong reason why 1.*I*I has an > imaginary part (equal to 0., but it's there). For instance neither I*I*1. > nor 1.*(I*I) have any imaginary part. 1) Remember that floating point arithmetic is not associative, and need not be commutative. 2) Using the standard formulas for complex arithmetic (a+bI)(c+dI) = (a*c - b*d) + I (a*d + b*c) [ 4 multiplications ], we obtain: (0 + 1.*I) * (0 + I) = (0*0 - 1.) + I*(0*1. + 0*1) = -1. and imaginary part is indeed an exact 0. 3) Unfortunately we use Karatsuba (aka 3M) instead of standard formulas, and compute (a+bI)(c+dI) = (a*c - b*d) + I ((a+b)*(c+d) - a*c - b*d) [ 3 multiplications ]. There the imaginary part becomes (0 + 1.)*(0 + 1) - (0*0) - (1.*1) = 0., NOT an exact 0 ! So, yes, this is expected. Cheers, K.B. -- Karim Belabas Tel: (+33) (0)5 40 00 26 17 Universite Bordeaux 1 Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux.fr/~belabas/ F-33405 Talence (France) http://pari.math.u-bordeaux.fr/ [PARI/GP]