hudsonb
01/21/2019, 5:23 PMfun someMath(phi: Double) {
var phi = phi
// ....
}
The one place that method parameters being final seems to annoy me is when I'm writing mathematical functions.altavir
01/21/2019, 5:35 PMelizarov
01/21/2019, 6:01 PMtailrec
, e.g. instead of
fun gcd(n0: Int, m0: Int): Int {
var n = n0
var m = m0
while (m != 0) m = (n % m).also { n = m }
return n
}
write:
tailrec fun gcd(n: Int, m: Int): Int =
if (m != 0) gcd(m, (n % m)) else n
hudsonb
01/22/2019, 7:20 PMphi0
but I've been porting some math heavy code over to Kotlin that reuses the method params, and I've caused more than one bug by neglecting to change a usage of phi
over to phi0
which is what makes it temptinghudsonb
01/22/2019, 7:21 PMtailrec
would be a good solutionhudsonb
01/22/2019, 7:27 PMhudsonb
01/22/2019, 7:36 PMinternal fun exponential(a: Double, b: Double, y: Double): (Double) -> Double {
a = a.pow(y)
b = b.pow(y) - a
y = 1.0 / y
return { t -> (a + t * b).pow(y) }
}
elizarov
01/22/2019, 10:13 PMelizarov
01/22/2019, 10:14 PMhudsonb
01/22/2019, 10:19 PMhudsonb
01/22/2019, 10:21 PMc = ((a = c) - b) / 2
🤪hudsonb
01/22/2019, 10:34 PMif (meridian
? polar
? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon ? phi0 : phi1)
: phi0 <= q[1] && q[1] <= phi1
: delta > pi ^ (lambda0 <= q[0] && q[0] <= lambda1))