[R] BUG: atan(1i) / 5 = NaN+Infi ?

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Fri Sep 6 01:55:09 CEST 2024


> x <- complex(imag = Inf)
> x
[1] 0+Infi
> x*1
[1] NaN+Infi
> x+0
[1] 0+Infi

R does the addition and subtraction "coordinatewise"; the C library handles
everything else. This results in 2 different ways the point at infinity is
printed.

(Correction requested if this is wrong)

Bert

On Thu, Sep 5, 2024 at 4:07 PM Jeff Newmiller via R-help <
r-help using r-project.org> wrote:

> atan(1i) -> 0 + Inf i
> complex(1/5) -> 0.2 + 0i
> atan(1i) -> (0 + Inf i) * (0.2 + 0i)
> -> 0*0.2 + 0*0i + Inf i * 0.2 + Inf i * 0i
> infinity times zero is undefined
> -> 0 + 0i + Inf i + NaN * i^2
> -> 0 + 0i + Inf i - NaN
> -> NaN + Inf i
>
> I am not sure how complex arithmetic could arrive at another answer.
>
> I advise against messing with infinities... use atan2() if you don't
> actually need complex arithmetic.
>
> On September 5, 2024 3:38:33 PM PDT, Bert Gunter <bgunter.4567 using gmail.com>
> wrote:
> >> complex(real = 0, imaginary = Inf)
> >[1] 0+Infi
> >
> >> Inf*1i
> >[1] NaN+Infi
> >
> >>> complex(real = 0, imaginary = Inf)/5
> >[1] NaN+Infi
> >
> >See the Note in ?complex for the explanation, I think.  Duncan can correct
> >if I'm wrong.
> >
> >-- Bert
> >
> >On Thu, Sep 5, 2024 at 3:20 PM Leo Mada <leo.mada using syonic.eu> wrote:
> >
> >> Dear Bert,
> >>
> >> These behave like real divisions/multiplications:
> >> complex(re=Inf, im = Inf) * 5
> >> # Inf+Infi
> >> complex(re=-Inf, im = Inf) * 5
> >> # -Inf+Infi
> >>
> >> The real division / multiplication should be faster and also is well
> >> behaved. I was expecting R to do the real division/multiplication on a
> >> complex number. Which R actually does for these very particular cases;
> but
> >> not when only Im(x) is Inf.
> >>
> >> Sincerely,
> >>
> >> Leonard
> >>
> >> ------------------------------
> >> *From:* Bert Gunter <bgunter.4567 using gmail.com>
> >> *Sent:* Friday, September 6, 2024 1:12 AM
> >> *To:* Duncan Murdoch <murdoch.duncan using gmail.com>
> >> *Cc:* Leo Mada <leo.mada using syonic.eu>; r-help using r-project.org <
> >> r-help using r-project.org>
> >> *Subject:* Re: [R] BUG: atan(1i) / 5 = NaN+Infi ?
> >>
> >> Perhaps
> >>
> >> > Inf*1i
> >> [1] NaN+Infi
> >>
> >> clarifies why it is *not* a bug.
> >> (Boy, did that jog some long dusty math memories :-)  )
> >>
> >> -- Bert
> >>
> >> On Thu, Sep 5, 2024 at 2:48 PM Duncan Murdoch <murdoch.duncan using gmail.com
> >
> >> wrote:
> >>
> >> On 2024-09-05 4:23 p.m., Leo Mada via R-help wrote:
> >> > Dear R Users,
> >> >
> >> > Is this desired behaviour?
> >> > I presume it's a bug.
> >> >
> >> > atan(1i)
> >> > # 0+Infi
> >> >
> >> > tan(atan(1i))
> >> > # 0+1i
> >> >
> >> > atan(1i) / 5
> >> > # NaN+Infi
> >>
> >> There's no need to involve atan() and tan() in this:
> >>
> >>  > (0+Inf*1i)/5
> >> [1] NaN+Infi
> >>
> >> Why do you think this is a bug?
> >>
> >> Duncan Murdoch
> >>
> >> ______________________________________________
> >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> https://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> >______________________________________________
> >R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list