O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The log (expr) function

The log (expr) function is the inverse of the exp(expr) function. The log (expr) function returns the natural logarithm of the expression given as an argument. The expression used as an argument must evaluate to a positive number or an error message NaN (not a number) will be thrown by the function.

In addition to the error message, it will print a warning message if a negative number is used as an argument to the log() function. The following code block shows an example of a  log(expr) function:

$ vi logfunc.awkBEGIN    {    print "log(5)    = ", log(5);    print "log(0)    = ", log(0);    print "log(-1)    = ", log(-1);}$ awk -f logfunc.awk

The output of the execution of the previous code is as follows :

log(5)    =  1.60944log(0) = -inf ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required