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
Weird Lua OOP Lib
Hand positions in a circle
Non-Lua core for new scripting languages (Beta)
PAID HACK PuBG
Personal Use (Among Us)
Code golf - ASCII art #1
quick sort
Truly random numbers (Lua)
Eliminatoria minigame
Brainfuck Interpreter (Lua) [reposted]