Gives the square root of a number System unit
 function Sqrt(Number   Extended):Extended;
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
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
SqrGives the square of a number
SumReturn the sum of an array of floating point values
 Download this web site as a Windows program.

Example code : Find the square root of various values
  number, squareRoot : Extended;

  // 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]);
Show full unit code
  Square root of 225.0 = 15.0
  Square root of 3.456 = 1.859032006180
  Square root of Infinity = INF
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page