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

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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




 
Example code : Find the square root of various values
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;
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 2002 - 2017. All rights reserved.  |  Home Page