From WikiChip
log10
Revision as of 23:32, 22 November 2015 by 109.236.84.27 (talk) (Created page with "'''log10''' is a function in many programming languages that returns the common logarithm of the input. == Implementation == Log base 10 can be calcu...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

log10 is a function in many programming languages that returns the common logarithm of the input.

Implementation

Log base 10 can be calculated using the following formula.

Equation log Subscript 10 Baseline left-parenthesis x right-parenthesis equals StartFraction ln left-parenthesis x right-parenthesis Over ln left-parenthesis 10 right-parenthesis EndFraction or log Subscript 10 Baseline left-parenthesis x right-parenthesis equals StartFraction log Subscript 2 Baseline left-parenthesis x right-parenthesis Over log Subscript 2 Baseline left-parenthesis 10 right-parenthesis EndFraction

An unoptimized implementation of log10 in C might look like:

#define LOG10 2.30258509299404568401799145468436421
double log10(double x)
{
    if (x < 0)
    {
        errno = EDOM;
        return -HUGE_VAL;
    }
    else if (x == 0)
    {
        errno = ERANGE;
        return -HUGE_VAL;
    }

    return log(x) / LOG10;
}

Language support

Language Function Package/Module
C log10 math.h
C++ log10 cmath
Go Log10 math
Haskell -
Java log10 java.lang.Math
Lisp log10
Lua log10 math
mIRC log10
Pascal -
Perl -
PHP log10
Python log10 math
Ruby log10 Math

See also