COHERENT manpages

This page displays the COHERENT manpage for log() [Compute natural logarithm].

List of available manpages
Index


log() -- Mathematics Function (libm)

Compute natural logarithm
#include <math.h>
double log(z) double z;

log() returns the natural (base e) logarithm of its argument z.

Example

The  following example  is  by Sanjay  Lal (sanjayl@tor.comm.mot.com).   It
returns the amount of a quantity of radioactive material that remains after
the passage  of a period of  time.  Use it when  planning your next nuclear
dump.  It takes three arguments:  the amount of material, in kilograms; the
half life, in  years; and the time passed, in  years.  These can be decimal
fractions.

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

main(argc, argv)
int argc; char *argv[];
{
    double num, thalf, time;

    if (argc != 4) {
        fprintf(stderr,"Usage: %s amount halflife time\n", argv[0]);
        exit (EXIT_FAILURE);
    }

    num = atof (argv[1]);
    thalf = atof (argv[2]);
    time = atof (argv[3]);
    printf("%f\n", num * exp ( -log(2.0) * (time / thalf)));
}

See Also

log10(),
libm
ANSI Standard, §7.5.4.4
POSIX Standard, §8.1

Diagnostics

When a  domain error occurs (z  is less than or equal  to zero), log() sets
errno to EDOM and returns zero.