diff --git a/README.md b/README.md index 9878788..cb84580 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ Currently supported: - sin/cos/tan -- exp/exp2/exp10 -- log/log2/log10 +- exp/exp2/exp10/expm1 +- log/log2/log10/log1p - sinh/cosh/tanh - arcsinh - sigmoid diff --git a/include/math_approx/src/log_approx.hpp b/include/math_approx/src/log_approx.hpp index 11be37b..e778690 100644 --- a/include/math_approx/src/log_approx.hpp +++ b/include/math_approx/src/log_approx.hpp @@ -180,4 +180,10 @@ constexpr T log10 (T x) { return log>, order, C1_continuous> (x); } + +template +constexpr T log1p (T x) +{ + return log>, order, C1_continuous> ((T) 1 + x); +} } diff --git a/include/math_approx/src/pow_approx.hpp b/include/math_approx/src/pow_approx.hpp index b66b60b..a48efb6 100644 --- a/include/math_approx/src/pow_approx.hpp +++ b/include/math_approx/src/pow_approx.hpp @@ -216,4 +216,10 @@ constexpr T exp10 (T x) { return pow>, order, C1_continuous> (x); } + +template +constexpr T expm1 (T x) +{ + return pow>, order, C1_continuous> (x) - (T) 1; +} } diff --git a/tools/plotter/plotter.cpp b/tools/plotter/plotter.cpp index b1acf88..97b7820 100644 --- a/tools/plotter/plotter.cpp +++ b/tools/plotter/plotter.cpp @@ -62,13 +62,13 @@ int main() { plt::figure(); const auto range = std::make_pair (-1.0f, 1.0f); - static constexpr auto tol = 1.0e-2f; + static constexpr auto tol = 1.0e-3f; const auto all_floats = test_helpers::all_32_bit_floats (range.first, range.second, tol); - const auto y_exact = test_helpers::compute_all (all_floats, FLOAT_FUNC (std::asinh)); + const auto y_exact = test_helpers::compute_all (all_floats, FLOAT_FUNC (std::expm1)); // plot_ulp_error (all_floats, y_exact, FLOAT_FUNC ((math_approx::asinh<5>)), "asinh-5"); - plot_ulp_error (all_floats, y_exact, FLOAT_FUNC ((math_approx::asinh<6>) ), "asinh-6"); - plot_ulp_error (all_floats, y_exact, FLOAT_FUNC ((math_approx::asinh<7>) ), "asinh-7"); + plot_error (all_floats, y_exact, FLOAT_FUNC ((math_approx::expm1<5>) ), "expm1-5"); + plot_error (all_floats, y_exact, FLOAT_FUNC ((math_approx::expm1<6>) ), "expm1-6"); plt::legend ({ { "loc", "upper right" } }); plt::xlim (range.first, range.second);