Skip to content

Commit

Permalink
Improve accuracy of trig.
Browse files Browse the repository at this point in the history
- Add MATLAB scripts for Padé approximation.
- Changed algorithm of `_cos`.
  • Loading branch information
ZCG-coder committed Jun 27, 2024
1 parent 12b6637 commit 8ab7845
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
/Steppable.build/

# MATLAB scripts
*.asv
Binary file added res/approximation_scripts/Ln.mlx
Binary file not shown.
Binary file added res/approximation_scripts/Trig.mlx
Binary file not shown.
12 changes: 9 additions & 3 deletions src/trig/trig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,15 @@ namespace steppable::__internals::arithmetic
{
// double x2 = x * x;
auto x2 = multiply(x, x, 0);
// return (12 - 5 * x2) / (12 + x2); // Padé approximant
auto a = subtract("12", multiply("5", x2, 0), 0);
auto b = add("12", x2, 0);
auto x4 = multiply(x2, x2, 0);
// (313*x^4 - 6900*x^2 + 15120)/(13*x^4 + 660*x^2 + 15120) // Padé approximant
// 4 2
// 313x - 6900x + 15120
// ------------------------
// 4 2
// 13x + 660x + 15120
auto a = add(subtract(multiply("313", x4, 0), multiply("6900", x2, 0), 0), "15120", 0);
auto b = add(add(multiply("13", x4, 0), multiply("660", x2, 0), 0), "15120", 0);
return standardizeNumber(divide(a, b, 0, decimals * 2));
}
// otherwise use recursion
Expand Down

0 comments on commit 8ab7845

Please sign in to comment.