From APL Wiki
(Redirected from Absolute Value)
Jump to navigation Jump to search

Magnitude (|), or Absolute Value, is a monadic scalar function which gives the absolute value of a real or complex number. Magnitude shares the glyph | with the dyadic arithmetic function Residue.


      |0 1 2 ¯1 ¯2
0 1 2 1 2
      |0J2 ¯3J¯4
2 5


The magnitude of any number is a non-negative real number.

For real numbers, the magnitude equals the original number times (or divided by, for non-zero numbers) its sign.

      v←0 1E¯100 20 1E300 ¯1E¯100 ¯20 ¯1E300
0 1 1 1 1 1 1

For complex numbers, the magnitude is defined as the Euclidean distance from the number 0 on the complex plane.

      Dist←{0.5*⍨+.×⍨9 11○⍵} ⍝ Square root of square sum of real and imaginary parts
      Dist¨ 0 1J2 ¯3J4
0 2.236067977 5
      |0 1J2 ¯3J4
0 2.236067977 5
Works in: Dyalog APL

Any real or complex number is equal to the product of its signum and magnitude.

      (⊢ ≡ ××|) 0 1 1E¯300 ¯2.5 0J3.5 ¯3J¯4
Works in: Dyalog APL

See also

External links


APL built-ins [edit]
Primitives (Timeline) Functions
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector