The log()
function in Ruby calculates the logarithm of a number to the base, or calculates the natural logarithm of a number if the user does not specify the base.
Figure 1 shows the mathematical representation of the log()
function.
log(number, base)
This function requires two parameters:
base
of the log()
returns the logarithm of a number to the base sent as a parameter.
The
log()
function calculates the natural logarithm of a number if the base is not provided, i.e.,log(y,e)
.
#number without baseprint "log(10) : ", Math.log(10), "\n"#number with baseprint "log(3,3) : ", Math.log(3,3), "\n"#errors#base is 0 and number is 0print "log(0,0) : ", Math.log(0,0), "\n"#base is 0print "log(3,0) : ", Math.log(3,0), "\n"#number is 0print "log(0) : ", Math.log(0), "\n"