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 logarithm of x+1
. The result of
log1pf(x)
is generally expected to be more accurate than that of
logf(x+1)
when the magnitude of x is small.
Remarks
A domain error occurs if x
is less than 1. A range error
might occur if the argument equals 1.
Example
#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