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

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Fri Sep 6 11:54:23 CEST 2024


On 2024-09-06 12:44 a.m., Richard O'Keefe wrote:
> 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).

I would only disagree with the statement above by distinguishing between 
a "bug" (where R is not behaving as documented) and a "design flaw" 
(where it is behaving as documented, but the behaviour is undesirable).

I think this is a design flaw rather than a bug.

The distinction is important:  if it is a design flaw, then a change is 
harder, because users who rely on the behaviour deserve more help in 
adapting than those who rely on a bug.  Bugs should be fixed.  Design 
flaws need thinking about, and sometimes shouldn't be fixed.

On the other hand, I was unable to find documentation saying that the 
current behaviour is intended, so I could be wrong.

Duncan Murdoch

> 
> 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