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;
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
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

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;
  // The System unit does not need to be defined
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  number, squared : Byte;
  float : Extended;

  // 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]);
Hide full unit code
   15 squared = 225
   17 squared = 33 (see code above)
   Infinity squared = INF
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page