Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Newton-Raphson method for the square root
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
--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))
[
+
]
Show input
Absolute running time: 1.51 sec, cpu time: 0.02 sec, memory peak: 5 Mb, absolute service time: 1,62 sec
edit mode
|
history
|
discussion
122.82914963477 122.82914963477