1. Perl
  2. builtin functions
  3. here

log function - find logarithm

You can use the log function to find the natural logarithm. You can also use the base transformation to calculate the logarithm of any base.

Find the natural logarithm

Use the log function to find the natural logarithm. The natural logarithm is the logarithm whose base is the Napier number e.

log(10);

Find the common logarithm

The common logarithm is a logarithm with a base of 10. You can use the logarithms change formula to find the logarithm of any base.

sub log10 {
  my $x = shift;
  return log($x)/log(10);
}

Example program

This is an example to find the logarithm using the log function.

use strict;
use warnings;

# The base of the logarithm is the Napier number e;
print "(1) Natural logarithm\n";
print "log(3) =" . Log (10). "\n\n";

print "(2) Common logarithm\n";
print "log10 (100) =" . Log10 (100) . "\n";

# A function to find the logarithm with a base of 10 (using the logarithms of the base)
sub log10 {
  my $x = shift;
  return log($x)/log(10);
}

Related Informatrion