CE-Programming / toolchain

Toolchain and libraries for C/C++ programming on the TI-84+ CE calculator series
https://ce-programming.github.io/toolchain/index.html
GNU Lesser General Public License v3.0
527 stars 53 forks source link

log1pf is inaccurate for small x #515

Closed ZERICO2005 closed 2 weeks ago

ZERICO2005 commented 3 weeks ago

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

ZERICO2005 commented 2 weeks ago

This has been resolved in this pull request: https://github.com/CE-Programming/toolchain/pull/516