FreePascal Information Logo Friend of FreePascal Compiler Title
Articles with Feedback, FPC News Library, PDF Collection, Mail Lists, Books, Newsgroups, IRC Open online discussion areas Research and Tutorials Tools, Compilers and Utilities Blurbs about us, advertising, etc.
Welcome to the FoFPC Pascal Language ABS

abs


     Calculate absolute value. Abs returns the absolute value of a negative or positive variable. It does this by removing a negative sign, if found. The result of the function has the same type as its argument, which can be any numerical type.

     The number can be any numeric type, and can even be a variant, as long as it can be converted to a number. For example, a variant set a string '-1.23' will work find. Always, abs converts the variants to an extended floating point of number prior to removing any negative sign, even if the result is an interger value.

     Floating point numbers can be set to extreme values, such as infinity (see the example). The abs function simply removes the negative sign of these, so that -INF becomes INF.

Example

    Download Source IconDownload This Source for Free Pascal
var
  floatvar, bigFloat : single;
  int : Integer;
  varVar : Variant;

begin
  floatvar := -1.5;       // Small negative floating point number
  bigFloat := -4.56E100;  // Infinite negative floating point number
  int      := -7;         // Negative integer
  varVar   := '-98';      // Variants are converted to floating point!

  Writeln('Abs(floatvar) = ',Abs(floatvar));
  Writeln('Abs(bigFloat) = ',Abs(bigFloat));
  Writeln('Abs(int) = ',Abs(int));

  // Variants are converted into Extended floating types
  floatvar := Abs(varVar);
  Writeln('Abs(varVar) = ',floatvar);
end.

Output

Abs(floatvar) =  1.5000000000000000E+0000
Abs(bigFloat) =                      +Inf
Abs(int) = 7
Abs(varVar) =  9.800000000E+01

See Also

Div, Mod, Round, Trunc.
 Links and Products we find useful



ButtonGenerator.com
Valid XHTML 1.0 Transitional Internet Map
Programmer's Heaven
grat-i-fi-ca-tion - noun
the state of being gratified; great satisfaction.


"Your research documents are head on ... I look forward to seeing more notes on your research."

Brian Ellixson
FreePascal User
Locations of visitors to this page world map hits counter
Copyright 2009 by 3F, LLC. All rights reserved. Worldwide.
Your request was processed by server #2 in 0.004328 secs.

sponsor
Click to visit our paid sponsor