RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.Sqr Function

Returns the square of a number.

Pascal
function Sqr(X: Extended): Extended; overload;
function Sqr(X: Integer): Integer; overload;
C++
Extended Sqr(Extended X);
int Sqr(int X);

In Delphi code, the Sqr function returns the square of the argument. 

X is a floating-point expression. The result, of the same type as X, is the square of X, or X*X.  

Delphi Examples: 

 

{
This example uses the System Sqr and Sqrt functions to calculate
the some mathematical values.
}

procedure TForm1.Button1Click(Sender: TObject);
var
  S, Temp: string;
begin
   Str(Sqr(5.5):3:1, Temp);
   S := '5.5 squared is ' + Temp + #13#10;
   MessageDlg(S, mtInformation, [mbOk], 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  S, Temp: string;
begin
   Str(Sqrt(2.0):5:4, Temp);
   S := S + 'The square root of 2 is ' + Temp;
   MessageDlg(S, mtInformation, [mbOk], 0);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!