Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Newton-Raphson method for the square root
--lua 5.3 local function sqrt(n) n = assert(tonumber(n), "expected number, got " .. type(n)) assert(n == n and n ~= math.huge, "expected a finite value") assert(n > 0, "expected a positive value") local x = 1 while true do local r = x - (x^2 - n) / (2*x) if math.abs(r - x) <= 10^-15 * r then return r end x = r end end local num = 15087 print(sqrt(num), math.sqrt(num))
run
|
edit
|
history
|
help
0
Properties in Lua
Surface Area of things (Incomplete)
Testingassets
Convert MySQL 'framed' table into CSV
RSA KEY GENERATOR (LUA)
Hakusu
quick sort
Weird Lua OOP Lib
aaa
1