From 07408e302de1ad9cda6d1b114b5f2d2c9ce6d719 Mon Sep 17 00:00:00 2001 From: jatin Date: Sun, 14 Jan 2024 11:27:04 -0800 Subject: [PATCH] Updating docs --- .gitignore | 1 + README.md | 35 ++++++++++++++++++++++--- include/math_approx/src/trig_approx.hpp | 4 ++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 48854f7..5463156 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ .vscode/ build*/ +*.zip .DS_Store diff --git a/README.md b/README.md index dcb4c9b..2c4ef3d 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ Currently supported: - log/log2/log10/log1p - sinh/cosh/tanh - arcsinh/arccosh/arctanh -- sigmoid -- Wright-Omega function -- Dilogarithm function +- [Sigmoid function](https://en.wikipedia.org/wiki/Sigmoid_function) +- [Wright-Omega function](https://en.wikipedia.org/wiki/Wright_omega_function) +- [Dilogarithm function](https://en.wikipedia.org/wiki/Dilogarithm) At the moment, most of these implementations have been "good enough" for my own use cases (both in terms of performance and accuracy). That @@ -27,6 +27,33 @@ approximations, either by: then please get in touch with a GitHub issue or pull request! +## Usage + +### With CMake + +`math_approx` is set up as a CMake `INTERFACE` library. To use it as +such, you'll need to add the following to your `CMakeLists.txt` file: + +```cmake +add_subdirectory(math_approx) +target_link_libraries( math_approx) +``` + +And then in your C++ code, you can use the approximations like so: + +```cpp +#include + +constexpr auto sin_half = math_approx::sin<5> (0.5f); +``` + +### Without CMake + +To use `math_approx` without CMake, you'll need to add +`/path/to/repo/include` to your include path. If you're +compiling your program with MSVC, you may also need to +add the pre-processor definition `_USE_MATH_DEFINES`. + ## A few other thoughts ### Accuracy vs. Performance @@ -44,7 +71,7 @@ polynomial approximations, I've tried to provide the details for how those polynomials were derived, by providing a zipped folder containing the Mathematica notebooks that were used to derive the polynomials. Since not everyone has access to -Mathematica, the folder also contains a PDF version of the +Mathematica, the folder also contains a PDF version of each notebook. At the moment, I'm planning to upload an updated copy of the zipped folder with each release of the library, but if I can think of a better method of distribution, that diff --git a/include/math_approx/src/trig_approx.hpp b/include/math_approx/src/trig_approx.hpp index e93257b..8dba67a 100644 --- a/include/math_approx/src/trig_approx.hpp +++ b/include/math_approx/src/trig_approx.hpp @@ -48,7 +48,9 @@ namespace trig_detail return select (x >= (T) 0, mod, mod + pi) - half_pi; } - // for polynomial derivations, see notebooks/sin_approx.nb + // Polynomials were derived using the method presented in + // https://mooooo.ooo/chebyshev-sine-approximation/ + // and then adapted for various (odd) orders. template constexpr T sin_poly_9 (T x, T x_sq)