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 doubleUsage:
result = Sqr( number )Parameters
- number — The number (greater than or equal to zero).
Return Value
Returns the square root of number.
- If
numberequals zero, returns0.0. - If
numberis 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.5Differences from QB
- None.