Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Get logarithm of base 10

by tamaguchi (Pilgrim)
on Feb 28, 2006 at 07:46 UTC ( [id://533328]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

tamaguchi has asked for the wisdom of the Perl Monks concerning the following question:

Hello all As I know it natural logarithm of a number "$number" is written in perl as: log($numer) but how is it possible to get the logarithm with base 10 or other logartms such as with base 2 etc. Thank you for any help.

2006-02-28 Retitled by jdporter, as per Monastery guidelines
Original title: 'Logarithms'

Replies are listed 'Best First'.
Re: Get logarithm of base 10
by dempa (Friar) on Feb 28, 2006 at 07:51 UTC
    From "perldoc -f log":

    To get the log of another base, use basic algebra: The base-N log of a number is equal to the natural log of that number divided by the natural log of N. For example:
    sub log10 { my $n = shift; return log($n)/log(10); }

    -- 
    dempa

Re: Get logarithm of base 10
by northwind (Hermit) on Feb 28, 2006 at 08:00 UTC

    Or if you wanted base N (where N could be 2, π, 10, 16, etc.)...

    sub log_N { my $num = shift; my $base = shift; return log($num)/log($base); }

Re: Get logarithm to base 10
by ChemBoy (Priest) on Feb 28, 2006 at 14:25 UTC

    As an alternative to the techniques already mentioned, you could always use POSIX 'log10'; (assuming that's not too easy ;-).



    If God had meant us to fly, he would *never* have given us the railroads.
        --Michael Flanders

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://533328]
Approved by Corion
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.