末尾再帰関数 tailrec

https://kotlinlang.org/docs/functions.html#tail-recursive-functions

末尾再帰関数の場合は、tailrec キーワードを付けることで、コンパイラが最適化し、高速化する。

val eps = 1E-10 // "good enough", could be 10^-15

tailrec fun findFixPoint(x: Double = 1.0): Double =
    if (Math.abs(x - Math.cos(x)) < eps) x else findFixPoint(Math.cos(x))