This is an old revision of the document!
The Sqr function returns the square root of a numeric value. The square root of a number $x$ is a value $y$ such that $y^2 = x$. This is a basic yet essential mathematical operation used in various fields, including distance calculations (Pythagorean theorem), signal processing, root-mean-square (RMS) power calculations, and physics-based motion simulations.
[Image of square root function graph]
On the Cubloc platform, the Sqr function is optimized for efficiency. To maintain the highest degree of precision, especially when the input is not a perfect square, it is highly recommended to use the Single data type for both the input value and the result.
Sqr accepts any non-negative real number. Attempting to calculate the square root of a negative number may result in a runtime error or an undefined result, as the system does not support imaginary numbers.
Example
Dim A As Single Dim B As Single B = 25.0 A = Sqr(B) ' Returns 5.0
[Image of Pythagorean theorem formula]
Usage Tip: When calculating the distance between two points $(x1, y1)$ and $(x2, y2)$, the Sqr function is used in conjunction with the Pythagorean theorem:
Distance = Sqr((x2-x1)^2 + (y2-y1)^2)