The current implementation of log1pf(float) does return logf(1.0f + x). When x is small, 1.0f + x will lose precision, or round to 1.0f. Going off the taylor series for ln(x + 1), this can be fixed by using return x for small values of x, or return x - 0.5f * (x * x) for slightly larger values of x.
Similar issues also apply to expm1f(float x) { return expf(x) - 1.0f; }, but I believe you are already aware of them
The current implementation of log1pf(float) does
return logf(1.0f + x)
. Whenx
is small,1.0f + x
will lose precision, or round to1.0f
. Going off the taylor series forln(x + 1)
, this can be fixed by usingreturn x
for small values ofx
, orreturn x - 0.5f * (x * x)
for slightly larger values ofx
.Similar issues also apply to
expm1f(float x) { return expf(x) - 1.0f; }
, but I believe you are already aware of them