How do you find the base y logarithm of a number x in Scala? I have searched the scala.math library and I can't find a way. It seems to have only log10(x) and ln(x).
This is a maths question :)
log<base y>(x) == log10(x)/log10(y) == ln(x)/ln(y)
Random link from the web that explains this:
http://www.purplemath.com/modules/logrules5.htm
For convenience, you can use a lambda function, e.g.,
scala> var log2 = (x: Double) => log10(x)/log10(2.0)
log2: Double => Double = <function1>
scala> log2(2)
res0: Double = 1.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With