SmartPascal
Sqrt
Function
Gives the square root of a number System unit
 function Sqrt ( Number :  Extended ) : Extended;
Description
The Sqrt function returns the square root of a Number.
 
The number must be a floating point type.
 
Special values are treated as follows:
Infinity  : Infinity
-0  : -0
NaN (Not a Number)  : NaN
Notes
Warning : the square root of a negative number is an imaginary number. In Delphi, use the Math routines to handle these.

Sqrt should raise an EInvalidOp exception when the Number is negative. In practice, the author's PC crashed (running Windows ME) when attempted.
Related commands
Sqr Gives the square of a number
Sum Return the sum of an array of floating point values
 
Example code : Find the square root 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, squareRoot : Extended;

begin
  // The square root of 225 = 15
  number  := 225;
  squareRoot := Sqrt(number);
  ShowMessageFmt('Square root of %f = %f',[number, squareRoot]);

  // The square root of 3.456 = 1.859...
  number  := 3.456;
  squareRoot := Sqrt(number);
  ShowMessageFmt('Square root of %7.3f = %12.12f',[number, squareRoot]);

  // The square root of infinity is still infinity
  number := Infinity;
  number := Sqrt(number);
  ShowMessageFmt('Square root of Infinity = %f',[number]);
end;
 
end.
Hide full unit code
   Square root of 225.0 = 15.0
   Square root of 3.456 = 1.859032006180
   Square root of Infinity = INF