Pavel Holoborodko
Pavel Holoborodko

Reputation: 557

Strange rules for complex multiplication with Infinity

Is there any explanation for following contradictory results in MATLAB?

>> Inf*0
ans =
   NaN

>> Inf*(0+1i)
ans =
            0 +        Infi

Is it a bug or is there any explanation for this?

UPDATE:

Interestingly that MATLAB, Maple & Mathematica all give the same results. BUT programming languages follow different philosophy. Check for example C99 Annex G 5.1.6. Same for FORTRAN. Well respected GNU MPC library also gives NaN + Inf*i.

My conclusion is that we need better & uniform semantic for complex operations and probably separate notion for complex infinity.

Upvotes: 3

Views: 358

Answers (1)

TroyHaskin
TroyHaskin

Reputation: 8401

It's not contradictory behavior since 0+1i is a number, albeit complex; the Inf does not distribute because of this. And since 0+1i does not have a magnitude of 0, multiplying it by Inf has a defined behavior; infinite magnitude in this instance. Apparently the arithmetic is such that the infinity is explicitly complex only, but that delves into dealing with infinity in the complex plane, which is an interesting discussion on its own.

If you change the number to one with zero magnitude, you have the same (Real) behavior:

>> Inf*(1+0i)   % Real with magnitude 1
ans =
   Inf

>> Inf*(0+1i)   % Imaginary with magnitude 1
ans =
   0.0000 +    Infi

>> Inf*(1/sqrt(2)+1i/sqrt(2))  % Complex with magnitude 1
ans =
      Inf +    Infi

>> Inf*(0+0i)  % Imaginary with magnitude 0
ans =
   NaN

Multiplying Inf by 0 and 0i separately also produces a NaN.

>> Inf*0+Inf*0i
ans =
   NaN

Upvotes: 6

Related Questions