Skip to content

Commit

Permalink
Updating docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jan 14, 2024
1 parent f6b932f commit 07408e3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.vscode/

build*/
*.zip

.DS_Store
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(<your_target> math_approx)
```

And then in your C++ code, you can use the approximations like so:

```cpp
#include <math_approx/math_approx.hpp>

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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion include/math_approx/src/trig_approx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
constexpr T sin_poly_9 (T x, T x_sq)
Expand Down

0 comments on commit 07408e3

Please sign in to comment.