Note that this feature is provided to simplify the transition of older code to Version 13.0. It does not prevent the generation and use of Complex Numbers using features new to 13.0 (such as explicitly specifying a Complex Number literal), and it will be removed in a future release of Dyalog APL.
The emphasis is mine but the sentiment signals to me that the described feature is something to be avoided.
I do want to suppress that creation but without signalling any new error and in such a way that individual elements that would be complex are returned as zero. So what I need is a function "real" that returns a one for each real number and a zero for each complex number in the argument. I can then define:
noncompex←{⍵×real ⍵}or derive:
noncomplex←×∘real⍨to clean my data.
The following functions serve where:
⎕ML←3 ⋄ ⎕IO←0 ⋄ _COMPLEX←⎕DR 1J1Global _COMPLEX avoids the scattering of arbitrary numeric constants around the code and its dynamic assignment avoids the outcome of a change of heart over those constants' arbitrary values.
real0←{We can shorten real1 by ignoring the zero case because:
1<≡⍵:∇¨⍵
_COMPLEX≠⎕DR ⍵:⍵=⍵
_COMPLEX≠⎕DR¨⍵
}
real1←{
{(1=⍵)∨(0=⍵)∨¯1=⍵}×⍵
}
∀⍵: (0=×⍵) ≤ ⍵=0i.e. signum ⍵ is zero implies that ⍵ is zero:
real2←{real2 is thus incorrect for zero values but we want zero anyway.
{(1=⍵)∨¯1=⍵}×⍵
}
Given that real2 is quicker in all circumstances than real0 I have no trouble in deciding which of the above to choose. But it crossed my mind that someone out there might know of a really obvious (to a mathematician) scalar method to extract the imaginary part of a complex number, let's call it i. Then all I need is
real3←0∘=∘iwhich would probably be twice as fast as real2.