-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqrt.kt
More file actions
25 lines (21 loc) · 663 Bytes
/
Copy pathSqrt.kt
File metadata and controls
25 lines (21 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package other
/**
* Algorithm for finding the square root of a number
*
* Wikipedia: https://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%BD%D0%B0%D1%85%D0%BE%D0%B6%D0%B4%D0%B5%D0%BD%D0%B8%D1%8F_%D0%BA%D0%BE%D1%80%D0%BD%D1%8F_n-%D0%BD%D0%BE%D0%B9_%D1%81%D1%82%D0%B5%D0%BF%D0%B5%D0%BD%D0%B8
*/
class Sqrt {
/**
* calculates the root of a number
*
* @number - number
* @return returns the root of a number
*/
fun compute(number: Double) : Double {
var value = number / 2
for (i in 1..100) {
value = (value + number / value) / 2
}
return value
}
}