Skip to content

SQR

Source: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgSqr Last revised: 2019-02-27

Returns a square root of a number.

Syntax

declare function Sqr ( byval number as double ) as double

Usage:

result = Sqr( number )

Parameters

  • number — The number (greater than or equal to zero).

Return Value

Returns the square root of number.

  • If number equals zero, returns 0.0.
  • If number is less than zero, returns a special "not defined" value (printed as "NaN" or "IND", platform dependent).

Description

This is the same as raising the argument to the one-half power: y = x ^ (1/2).

If a LongInt or ULongInt is passed to Sqr, it may be converted to Double precision first. For numbers over 2^52, this causes a very small loss of precision.

Sqr can be overloaded as an operator to accept user-defined types.

Examples

vb
' Example of Sqr function: Pythagorean theorem
Dim As Single a, b

Print "Pythagorean theorem, right-angled triangle"
Print
Input "Please enter one leg side length: ", a
Input "Please enter the other leg side length: ", b
Print
Print "The hypotenuse has a length of: " & Sqr( a * a + b * b )

Output:

Pythagorean theorem, right-angled triangle

Please enter one leg side length: 1.5
Please enter the other leg side length: 2

The hypotenuse has a length of: 2.5

Differences from QB

  • None.

See Also

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft