[R] BUG: atan(1i) / 5 = NaN+Infi ?
Richard O'Keefe
r@oknz @end|ng |rom gm@||@com
Fri Sep 6 06:44:01 CEST 2024
I expect that atan(1i) = (0 + infinity i) and that atan(1i)/5 = (0 +
infinity i)/5 = (0 + infinity i).
Here's what I get in C:
(0,1) = (0, 1)
atan((0,1)) = (0, inf)
atan((0,1))/5 = (0, inf)
Note the difference between I*infinity = (0,1)*infinity =
(0*infinity,1*infinity) = (NaN,infinity)
and (0,infinity)/5 = (0/5,infinity/5) = (0,infinity).
The former involves multiplying 0 by infinity, which yields NaN.
The latter does not.
> complex(1,0,Inf)*2
[1] NaN+Infi
There is no good reason for this. 0*2 is 0, not NaN.
In IEEE arithmetic, multiplying or dividing a complex number by a real number is
NOT the same as multiplying or dividing by the complex version of that
real number.
(0,Inf) * 2 = (0*2, Inf*2) = (0, Inf).
(0,Inf) * (2,0) = (0*2 - Inf*0, 0*0 + Inf*2) = (NaN, Inf).
There really truly is a bug here, and it is treating R*Z, Z*R, and Z/R
as if they were
the same as W*Z, Z*W, and Z/W where W = complex(1,R,0).
On Fri, 6 Sept 2024 at 10:12, Bert Gunter <bgunter.4567 using gmail.com> wrote:
>
> 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.
More information about the R-help
mailing list