Perl | log() Function Last Updated : 25 Jun, 2019 Comments Improve Suggest changes Like Article Like Report log() function in Perl returns the natural logarithm of value passed to it. Returns $_ if called without passing a value. log() function can be used to find the log of any base by using the formula: Syntax: log(value) Parameter: value: Number of which log is to be calculated Returns: Floating point number in scalar context Example 1: Perl #!/usr/bin/perl -w # Calculating log of base 10 # using log function print "log10(2): ", log10(2), "\n"; print "log10(7): ", log10(7), "\n"; print "log10(9): ", log10(9), "\n"; # Function for log10 calculator sub log10 { my $n = shift; # using pre-defined log function return log($n) / log(10); } Output: log10(2): 0.301029995663981 log10(7): 0.845098040014257 log10(9): 0.954242509439325 Example 2: Perl #!/usr/bin/perl -w # Calculating log of different # base using log function print "log3(2): ", log3(2), "\n"; print "log5(7): ", log5(7), "\n"; print "log2(9): ", log2(9), "\n"; # Function for log3 calculator sub log3 { my $n = shift; # using pre-defined log function return log($n) / log(3); } # Function for log5 calculator sub log5 { my $n = shift; # using pre-defined log function return log($n) / log(5); } # Function for log2 calculator sub log2 { my $n = shift; # using pre-defined log function return log($n) / log(2); } Output: log3(2): 0.630929753571457 log5(7): 1.20906195512217 log2(9): 3.16992500144231 Comment More infoAdvertise with us Next Article Perl | log() Function C Code_Mech Follow Improve Article Tags : Perl Perl-function Perl-Math-Functions Similar Reads Perl | exp Function The exp function in Perl calculates "e" raised to the power of the real number taken as the parameter. Here "e" is Eulerâs Number or the base of the Natural system of logarithms or commonly known as an irrational number that approximates to 2.718281828, and is one of the most important mathematical 2 min read Perl | abs() function This function returns the absolute value of its argument. If a pure integer value is passed then it will return it as it is, but if a string is passed then it will return zero. If VALUE is omitted then it uses $_ Syntax: abs(VALUE) Parameter: VALUE: It is a required number which can be either positi 2 min read Perl | cos() Function This function is used to calculate cosine of a VALUE or $_ if VALUE is omitted. The VALUE should be expressed in radians. Syntax: cos(VALUE) Parameters: VALUE in the form of radians Returns: Function returns cosine of VALUE. Example 1: Perl #!/usr/bin/perl # Calling cos function $var = cos(5); # Pri 1 min read Perl | sin() Function This function is used to calculate sine of a VALUE or $_ if VALUE is omitted. This function always returns a floating point. Syntax: sin(VALUE) Parameters: VALUE in the form of float Returns: Function returns sine of VALUE. Example 1: Perl #!/usr/bin/perl # Calling sin() function $var = sin(5); # Pr 1 min read Perl | File I/O Functions File handling in Perl is used to read data from an external file or to write data into an external file. This is very useful as it provides a platform to permanently store and retrieve data from files. File Handle A FileHandle associates a name to an external file, that can be used until the end of 4 min read Like