log
Find the logarithm of argument x with the base of a
log<return_type>(a, x);
will return the logarithm of the argument x with the base a, both given as arguments. The return_type specifies in which data type the result will be returned in, like shown in below example:
log<int>(20, 400); //2
log<float>(1.43, 543.18); //17.6066
Just like ln(x), log(a, x) isn't defined for all non-positive arguments x, as the compiler will throw an exception:
Error: Logarithm is undefined for non-positive values.
Because the ln(x) function is so precise, we can just use the:
formula to calculate the given logarithm.
Last updated