reciprocal of a complex number

General APL language issues
Post Reply
User avatar
giangiquario
Posts: 46
Joined: Thu Nov 26, 2009 8:55 am
Location: Milano, Italia

reciprocal of a complex number

Post by giangiquario »

In Dyalog 13.0

Code: Select all

     ÷ .5E160J.5e160
DOMAIN ERROR
      ÷5E159J5E159
     ∧


I think that it is a overflow pitfall.

I suggest to change the implementation of "reciprocal" into the interpreter.
For example you could do something like :

Code: Select all

Reci←{
     ReIm←{9 11○⍵}⍵
     recip←{>/|⍵:{q←÷/⌽⍵ ⋄ 1(-q)÷+/⍵×1 q}⍵
         {q←÷/⍵ ⋄ q ¯1÷+/⍵×q 1}⍵}ReIm ⍝(avoiding overflow)
     {+/1 0J1×⍵}recip
 }


In fact:

Code: Select all

     Reci .5E160J.5e160
1E¯160J¯1E¯160
Jay|Dyalog

Re: reciprocal of a complex number

Post by Jay|Dyalog »

Well spotted! I have raised this as issue 7628.

A very simple work around is to use divide instead of reciprocal:

Code: Select all

      1÷.5E160J.5e160
1E¯160J¯1E¯160


Thanks,
Jay.
Post Reply