Loic Grenie on Sat, 10 Mar 2007 19:25:21 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Desired behaviour ?


* Karim Belabas [2007-03-10 18:13]:
> * 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.

    I've read the code and I knew it was expected. The question was: is there
  a \underline{strong} reason, meaning: is it reasonable to change the
  semantics to gain between 1 and 3% on make bench ?

    After Bill's answer, my question has slightly changed though: is it
  important that it is 0.I instead of 0I ?

     Loïc