MyChat Scripts: function Sqrt, calculating a square root of a number
"For developers", "Server scripts", "Functions descriptions", "Mathematical", "Sqrt".
Calculating a square root of an integer or real positive number .
Syntaxt
function Sqrt(x: extended): extended;
Parameters and return values
Parameter |
Type |
Value |
x |
extended |
a number for calculating a square root. It can' t be a negative integer. |
Function result
Real integer. If the pamameteris x < 0, the function returns 0.
Example
var
i, iValue: integer;
x: extended;
s: string;
begin
for i := 100 downto 1 do begin
x := Sqrt(i);
iValue := Trunc(x);
if iValue = x then begin
s := IntToStr(iValue);
mLogScript(IntToStr(i), s + 'x' + s);
end;
end;
end.
Script work result
[13:28:56] (Log "Sqrt"): [10x10] 100
[13:28:56] (Log "Sqrt"): [9x9] 81
[13:28:56] (Log "Sqrt"): [8x8] 64
[13:28:56] (Log "Sqrt"): [7x7] 49
[13:28:56] (Log "Sqrt"): [6x6] 36
[13:28:56] (Log "Sqrt"): [5x5] 25
[13:28:56] (Log "Sqrt"): [4x4] 16
[13:28:56] (Log "Sqrt"): [3x3] 9
[13:28:56] (Log "Sqrt"): [2x2] 4
[13:28:56] (Log "Sqrt"): [1x1] 1
[13:28:56] (Run "Sqrt"): Script operation time: 3 ms
[13:28:56] (Run "Sqrt"): Script done successfully.