Function to obtain a modulus from a specified number (integer or real).

 

Syntax

function Abs(x: extended): extended;

 

Parameters and return values

Parameter

Type

Value

x

extended

number from which you need to obtain the modulus.

 

Function result

Returns an absolute value of a number.

 

Example


var
  i, x: integer;
begin
  for i := 1 to 10 do begin
    x := random(10) - 5;
    mLogScript(inttostr(round(abs(x))), inttostr(x));
  end;
end.


Script work result

[22:26:14] (Log "Abs"): [0] 0

[22:26:14] (Log "Abs"): [3] 3

[22:26:14] (Log "Abs"): [-2] 2

[22:26:14] (Log "Abs"): [0] 0

[22:26:14] (Log "Abs"): [1] 1

[22:26:14] (Log "Abs"): [3] 3

[22:26:14] (Log "Abs"): [4] 4

[22:26:14] (Log "Abs"): [-4] 4

[22:26:14] (Log "Abs"): [-3] 3

[22:26:14] (Log "Abs"): [-2] 2

[22:26:14] (Run "Abs"): Script operation time: 3 ms

[22:26:14] (Run "Abs"): Script done successfully.
 

See also

IntToStr
mLogScript

Random

Round