Skip to content

Commit

Permalink
Add log1p and expm1
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Dec 23, 2023
1 parent b5a1108 commit 89af9be
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions include/math_approx/src/log_approx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,10 @@ constexpr T log10 (T x)
{
return log<pow_detail::Base10<scalar_of_t<T>>, order, C1_continuous> (x);
}

template <int order, bool C1_continuous = false, typename T>
constexpr T log1p (T x)
{
return log<pow_detail::BaseE<scalar_of_t<T>>, order, C1_continuous> ((T) 1 + x);
}
}
6 changes: 6 additions & 0 deletions include/math_approx/src/pow_approx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,10 @@ constexpr T exp10 (T x)
{
return pow<pow_detail::Base10<scalar_of_t<T>>, order, C1_continuous> (x);
}

template <int order, bool C1_continuous = false, typename T>
constexpr T expm1 (T x)
{
return pow<pow_detail::BaseE<scalar_of_t<T>>, order, C1_continuous> (x) - (T) 1;
}
}
8 changes: 4 additions & 4 deletions tools/plotter/plotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> (all_floats, FLOAT_FUNC (std::asinh));
const auto y_exact = test_helpers::compute_all<float> (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);
Expand Down

0 comments on commit 89af9be

Please sign in to comment.