DelphiBasics
 SqrFunction Gives the square of a number System unit
 1 function Sqr ( Number :  Integer ) : Integer; 2 function Sqr ( Number :    Int64 ) : Int64; 3 function Sqr ( Number : Extended ) : Extended;
Description
The Sqr function returns the square of a Number.

Sqr(Number) = Number * Number

The number may be an integer or floating point type.

Integer, Int64 numbers

If the square of the number exceeds the capacity of the target variable, then the result is :

Result Mod Capacity

Extended numbers

If the square of the number exceeds the capacity, EOverFlow exception is raised.

Special values are treated as follows:

 Infinity, -Infinity : Infinity NaN (Not a Number) : NaN
Related commands
 Dec Decrement an ordinal variable Inc Increment an ordinal variable Sqrt Gives the square root of a number Sum Return the sum of an array of floating point values

 Example code : Find the square of various values // Full Unit code.// -----------------------------------------------------------// You must store this code in a unit called Unit1 with a form// called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses  // The System unit does not need to be defined  Math,  Forms, Dialogs; type  TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  end; var  Form1: TForm1; implementation{\$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); var   number, squared : Byte;   float : Extended; begin  // The square of 15 = 225   number  := 15;   squared := Sqr(number);   ShowMessageFmt('%d squared = %d',[number, squared]);   // The square of 17 = 289  // But result exceeds byte size, so result = 289 MOD 256 = 33   number  := 17;   squared := Sqr(number);   ShowMessageFmt('%d squared = %d (see code above)',[number, squared]);   // The square of infinity is still infinity   float := Infinity;   float := Sqr(float);   ShowMessageFmt('Infinity squared = %f',[float]); end; end. Hide full unit code 15 squared = 225   17 squared = 33 (see code above)   Infinity squared = INF