Name

Sqrt Function

Syntax

function Sqrt(Number: Floating-point type): Extended;

Description

The Sqrt function returns the positive square root of its argument. It is not a real function, but is expanded inline by the compiler.

Tips and Tricks

  • Delphi automatically converts Integer and Variant arguments to floating point. To convert an Int64 argument to floating point, add 0.0.

  • If Number is positive infinity, the result is positive infinity.

  • If Number is negative zero, the result is negative zero.

  • If Number is negative non-zero, negative infinity, or a signaling NaN, Delphi raises runtime error 6 (EInvalidOp).

  • If Number is a quiet NaN, the result is Number.

Example

function Hypotenuse(X, Y: Double): Double;
begin
  Result := Sqrt(Sqr(X) + Sqr(Y));
end;

See Also

Extended Type, Sqr Function

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.