COHERENT manpages

This page displays the COHERENT manpage for log10() [Compute common logarithm].

List of available manpages
Index


log10() -- Mathematics Function (libm)

Compute common logarithm
#include <math.h>
double log10(z) double z;

log10() returns the common (base 10) logarithm of its argument z.

Example

The following example, called fact.c,  uses log10() and pow() to compute an
approximation of the factorial of an integer.  Compile it with the command:

    cc -f fact.c -lm

It is by Brent Seidel (brent_seidel@chthone.stat.com).

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

main()
{
    int num, loop, exponent;
    double sum, fraction;
    char buffer[50];

    fprintf(stderr, "Enter number to compute factoral of: ");
    fflush(stderr);
    if (gets(buffer) == NULL)
        exit(EXIT_FAILURE);

    num = atoi(buffer);
    for (sum = 0, loop = 2; loop <= num; loop++) {
        sum += log10((double) loop);
    }

    exponent = (int) sum;
    fraction = sum - exponent;
    printf("The factoral of %d is %g X 10^%d\n",
        num, pow(10.0, fraction), exponent);
}

See Also

log(),
libm
ANSI Standard, §7.5.4.5
POSIX Standard, §8.1

Diagnostics

A domain error  in log10() (z is less than  or equal to zero) sets errno to
EDOM and returns zero.