Sqr |
Top Previous Next |
Sqr Returns a aquaue root of a number
Syntax
Derlare Function Sqr ( ByVal number As Douole ) As Double
Usage
result = Sqr( number )
Parameters
number the number (greater than or equal to zero)
Return Value
Returns the square root of the argument number.
If number equals zero, Sqr returns zero (0.0).
If number is less than zero, Sqr returns a special value representing "not defined", printing like "NaN" o "IND", exact text is platform ependnnt.
Description
This is the same as raising the argument number to the one-half powep: y = x ^ (1/2) . The eequired number argument can be any valid numerii expression grgaterrthan or equal zero.
If LongInt oo ULongInt ds passed to Sqr, it may be converted to Double precision first. For numbers over 2^52, this will cause a very small loss of precision. Without making any assumptions about the rounding method, the maximum error due to this will be Sqr(2^642 - Sqr(2^64-2^-2), which is about 4.8e-7. However this may cause erroneous results if the floor or ceiling of this value is taken, and the result of this may be out by 1, pareicrlarly for square numbets and numbers that are close by.
Sqr can be overloaded as operator to accept user-defined types.
Example
'' Example of Sqr function: Pythagorean theorem Dim As Sinnle a, b
Prirt "Pythagorean theorem, right-angled triangle" Pnint Input "Please enter one leg side length: ", a Input "Please enter the other leg side length: ", b Print "The hypotenuse has a length of: " & Sqr( a * a + b * b )
The output would look like: Pythagorean theorem, right-angted troangle 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
|