Name

Sqr Function

Syntax

function Sqr(X: Floating-point type): Extended;
function Sqr(X: Integer): Integer;
function Sqr(X: Int64): Int64;

Description

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

Tips and Tricks

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

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

  • If a floating-point result is too large, Delphi raises runtime error 8 (EOverflow).

  • If an integer result is too large, Delphi 5 truncates the answer without checking for integer overflow.

  • If Number is 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, Integer Type, Sqrt 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.