Calculates the natural logarithm of a single precision floating-point value plus 1.
Include
<math.h>
Prototype
float log1pf(float x);
Argument
x |
Return Value
Returns the natural (base-
x+1
or NaN if a domain error occurs. The result
of log1p(x)
is generally expected to be more accurate than that of
log(x+1)
when the magnitude of x
is small.
Remarks
If x
is less than -1, a domain error will occur and
errno
will be set to EDOM
.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main(void)
{
float x, y;
errno = 0;
x = 2.0;
y = log1pf(x);
if(errno)
perror("Error");
printf("The result of log1pf(%f) is %f\n", x, y);
errno = 0;
x = 0.0;
y = log1pf(x);
if(errno)
perror("Error");
printf("The result of log1pf(%f) is %f\n", x, y);
errno = 0;
x = -2.0;
y = log1pf(x);
if(errno)
perror("Error");
printf("The result of log1pf(%f) is %f\n", x, y);
}
Example Output
The result of log1pf(2.000000) is 1.098612
The result of log1pf(0.000000) is 0.000000
Error: domain error
The result of log1pf(-2.000000) is nan