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+InfiThere'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
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 at 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 at 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]]
Dear Duncan, Here is also the missing information: R version 4.4.1 (2024-06-14 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 10 x64 (build 19045) Regarding the results: atan(1i) # 0+Infi Re(atan(1i)) # 0 Im(atan(1i)) # Inf 0 + Inf i is a valid complex number: tan(atan(1i)) # 0+1i Inf / 5 # Inf Note: atan(1i) / 5 should have generated 0 + Inf * 1i; even the explicit complex number fails: complex(re=0, im = Inf) / 5 # NaN+Infi complex(re=Inf, im = Inf) / 5 # Inf+Infi I presume that R tries to do the complex division, although the real division is well defined. Sincerely, Leonard ________________________________ From: Duncan Murdoch <murdoch.duncan at gmail.com> Sent: Friday, September 6, 2024 12:40 AM To: Leo Mada <leo.mada at syonic.eu>; r-help at r-project.org <r-help at r-project.org> Subject: Re: [R] BUG: atan(1i) / 5 = NaN+Infi ? 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+InfiThere'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 -------------- next part -------------- A non-text attachment was scrubbed... Name: =?iso-8859-7?Q?5-(2019)-CEBP=E2-LIP_induces_cancer-type_metabolic_reprogr?= =?iso-8859-7?Q?amming_by_regulating_the_let-7LIN28B_circuit_in_mice.pdf?Type: application/pdf Size: 2136921 bytes Desc: =?iso-8859-7?Q?5-(2019)-CEBP=E2-LIP_induces_cancer-type_metabolic_reprogr?= =?iso-8859-7?Q?amming_by_regulating_the_let-7LIN28B_circuit_in_mice.pdf?URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20240905/85b49427/attachment-0001.pdf>
On 2024-09-05 6:12 p.m., Leo Mada wrote:> Dear Duncan, > > Here is also the missing information: > R version 4.4.1 (2024-06-14 ucrt) > Platform: x86_64-w64-mingw32/x64 > Running under: Windows 10 x64 (build 19045) > > Regarding the results: > atan(1i) > #?0+Infi > Re(atan(1i)) > # 0 > Im(atan(1i)) > #? Inf > > 0 + Inf i is a valid complex number: > tan(atan(1i)) > # 0+1i > > Inf / 5 > # Inf > > Note: atan(1i) / 5 should have generated 0 + Inf * 1i; even the explicit > complex number fails: > complex(re=0, im = Inf) / 5 > # NaN+Infi > complex(re=Inf, im = Inf) / 5 > # Inf+Infi > > I presume that R tries to do the complex division, although the real > division is well defined.I imagine that what happens is that when one operand is complex, both are coerced to complex and the operation is carried out. I had assumed this was documented in ?complex, but I don't see it there. Maybe it should be. If you want z/5 to be carried out using the correct mathematical approach, you'll probably have to define it yourself. For example, CxByReal <- function(num, denom) { if (is.complex(denom)) stop("this is for a real denominator!") complex(real = Re(num)/denom, imaginary = Im(num)/denom) } CxByReal(complex(real=0, imaginary=Inf), 5) # [1] 0+Infi Duncan Murdoch> > Sincerely, > > Leonard > > ------------------------------------------------------------------------ > *From:* Duncan Murdoch <murdoch.duncan at gmail.com> > *Sent:* Friday, September 6, 2024 12:40 AM > *To:* Leo Mada <leo.mada at syonic.eu>; r-help at r-project.org > <r-help at r-project.org> > *Subject:* Re: [R] BUG: atan(1i) / 5 = NaN+Infi ? > 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 >