[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 9.1 Abs

### Synopsis

    function Abs (i: integer type): integer type;

or

    function Abs (x: real type): real type;

or

    function Abs (z: Complex type): real type;

### Description

Returns the absolute value of the argument. For integer or real values of ``x'`, the definition is

    function Abs (x: integer or real type): integer or real type;
    begin
      if x < 0 then
        Abs := -x
      else
        Abs := x
    end;

whereas for complex values it is

    function Abs (x: Complex): Real;
    begin
      Abs := SqRt (x * Conjugate (x))
    end;

### Conforming to

The function ``Abs'` is defined in ISO-7185 Pascal; its application to complex values is defined in ISO-10206 Extended Pascal.

### Example

    program AbsDemo;
    var
      i1: Complex;
    begin
      WriteLn (Abs (42));             { 42 }
      WriteLn (Abs (-42));            { 42 }
      WriteLn (Abs (-12.1) : 0 : 1);  { 12.1 }
      i1 := Cmplx (1, 1);             { 1 + i }
      WriteLn (Abs (i1) : 0 : 3)      { 1.414, i.e. SqRt (2) }
    end.

### See also

section 9.260 Sqr.

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html