Re: [R] Inf +1i vs 1+Inf*1i

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Wed 13 Apr 2005 - 18:40:33 EST

Actually, the problem comes from "Inf * 1i" (or 1i * Inf) and the

          0 * Inf |-> NaN
which of course is `correct' in general, but a bit undesirable in the rule

   (a + bi) * (c + di) = (ac - bd) + (ad + bc)i

{and similarly in complex division}.

Note that the same problem also leads to

  > 1 * complex(re=0, im=Inf)
  [1] NaN+Infi

which is even more ugly,
since '1 * z' really should return 'z' for all z.

Martin

BTW: S-plus (6.2.1) also returns NaN

      (printing "NA". S+ has no complex versions of 'NaN')

>>>>> "MM" == Martin Maechler <maechler@stat.math.ethz.ch>
>>>>> on Wed, 13 Apr 2005 10:17:00 +0200 writes:

>>>>> "Robin" == Robin Hankin <r.hankin@soc.soton.ac.uk>
>>>>> on Wed, 13 Apr 2005 08:51:19 +0100 writes:

    Robin> Hi
    Robin> If I have

    Robin> a <- Inf + 1i

    Robin> then

    Robin> Re(a) is Inf, and Im(a) is 1, as expected.

    Robin> But if

    Robin> b <- 1 + Inf * 1i,

    Robin> then

    Robin> Im(b) = Inf , as expected, but Re(b) = NaN, which I didn't expect.

    Robin> Why this asymmetry?

    MM> I think this is a (very long standing) buglet in our complex     MM> arithmetic, since you can directly see

    >> 1+ 1i*Inf
    MM> [1] NaN+Infi

    Robin> How to define an object with Re(b)=1, Im(b)=Inf?

    MM> {Oscar already mentioned b <- complex(real=1, im=Inf) }

    MM> Martin Maechler, ETH Zurich

    MM> ______________________________________________
    MM> R-help@stat.math.ethz.ch mailing list
    MM> https://stat.ethz.ch/mailman/listinfo/r-help     MM> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Apr 13 18:47:27 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:07 EST