Next: , Up: Reference



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

Sqr.