Find the logarithm of a number in Scala

How do you find the base y logarithm of the number x in Scala? I searched the scala.math library and I cannot find a way. It seems to have only log10 (x) and ln (x).

+6
source share
2 answers

This is a math question :)

log<base y>(x) == log10(x)/log10(y) == ln(x)/ln(y) 

A random internet link that explains this:

http://www.purplemath.com/modules/logrules5.htm

+8
source

For convenience, you can use the lambda function, for example,

 scala> var log2 = (x: Double) => log10(x)/log10(2.0) log2: Double => Double = <function1> scala> log2(2) res0: Double = 1.0 
+2
source

Source: https://habr.com/ru/post/984972/


All Articles