Apl2ToDoNumericRangeAlgorithms
This is a sub-page of PhraseBook/ToDo/Apl2Idioms
N←⌈/NM ⍝ Maximum value of NM.
N←⌈/|NM ⍝ Maximum of magnitude of NM.
N←⌈/NM,0 ⍝ Maximum of positive value of NM.
N←N××.5-(⌈/NM)≠N←⌈/|NM ⍝ Maximum of magnitude of NM preserving sign.
N←⌊/NM ⍝ Minimum value of NM.
N←⌊/|NM ⍝ Minimum of magnitude of NM.
N←⌊/NM,0 ⍝ Maximum of negative value of NM.
N←N××.5-(⌊/NM)≠N←⌊/|NM ⍝ Minimum of magnitude of NM preserving sign.
IS←↑⍒N ⍝ Index of the largest item.
IO←N⍳⌈/N ⍝ Index of the largest item.
IS←↑⍋N ⍝ Index of the smallest item.
IO←N⍳⌊/N ⍝ Index of the smallest item.
FA←(×NA)|NA ⍝ Fractional part of number with sign.
FA←1||NA ⍝ Magnitude of fractional part of number.
FA←1|NA ⍝ Fractional part of number.
NA←|NA ⍝ Magnitude. Absolute Value of NA.
FA←0 1⊤NA ⍝ Integral+fractional part of positive number.
IA←(×NA)×⌊|NA ⍝ INTEGER. Truncate to whole number.
FA←(×NA)×(⌊.5+|NA÷NS)×NS ⍝ Rounding to nearest NSth.
IA←(×NA)×⌊.5+|NA ⍝ Rounding to nearest whole number.
IA←(×NA)×⌊(1≤2||NA)+|NA ⍝ Rounding to nearest even number.
FA←⍎(|IS)⍕NA ⍝ Rounding to IS decimal places.
N←N×N≤NS ⍝ Force to 0 any N greater than NS.
N←N×NS≤N ⍝ Force to 0 any N less than NS.
N←(>/N∘.>0 NS)/N ⍝ Keep everything in range [0,NS).
N←0⌈NS⌊N ⍝ Force N numbers to range 0≤N≤NS.
N←Nׯ1*B ⍝ Change sign on condition B.
NA←(⊂1 ¯1)×NA ⍝ Plus Minus. Number and its negative.
N←X+NS×⍳IS ⍝ Arithmetic progression vector.
N←X+NSׯ1+⍳IS ⍝ Arithmetic progression vector.
N←X+(×N)×⍳1+⌊|N←Y-X ⍝ Index Generator. Range from X to Y.
N←X+0,(×N)×⍳⌊|N←Y-X ⍝ Index Generator. Range from X to Y.
N←X+IS×⍳0⌈(IS≠0)+⌊(Y-X)÷IS ⍝ Index Generator with step IS. From X to Y.
N←X+ISׯ1+⍳0⌈(IS≠0)+⌊|(Y-X)÷IS ⍝ Index Generator with step IS. From X to Y.
N←εNX+⍳¨IX ⍝ Sequence from NX for IX items.
N←¯1+εNX+⍳¨IX ⍝ Sequence from NX for IX items.
NA←(×NAX)×(|NAY)||NAX ⍝ REMAINDER from division of NAX by NAY.
NA←NAY|NAX ⍝ MODULO of NAX and NAY.
NA←(×NAY)×|NAX ⍝ SIGN. Transfer of sign from NAY to NAX.
NA←NS+(-NS)|NA ⍝ Residue replacing 0 with NS.
APL Wiki