Skip to content

Commit

Permalink
[upstream_utils] Upgrade to GCEM 1.18.0 (#6805)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Jul 7, 2024
1 parent 450fae3 commit 1f92c59
Show file tree
Hide file tree
Showing 71 changed files with 516 additions and 170 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion upstream_utils/gcem_patches/0002-Add-hypot-x-y-z.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Subject: [PATCH 2/2] Add hypot(x, y, z)
1 file changed, 82 insertions(+), 3 deletions(-)

diff --git a/include/gcem_incl/hypot.hpp b/include/gcem_incl/hypot.hpp
index 00e10f899ace8f0da925fa9e46fa3f79f7e83aa0..13ea80c49d374c23434c1f9859bb6474184dc420 100644
index 22a402066430f4fde68f9d622ccdf7c646a3cbd6..4e7523ab85b75e5daf34a2ea34e1d98f79703ac9 100644
--- a/include/gcem_incl/hypot.hpp
+++ b/include/gcem_incl/hypot.hpp
@@ -27,6 +27,7 @@
Expand Down
2 changes: 1 addition & 1 deletion upstream_utils/update_gcem.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def main():
upstream_root = clone_repo("https://github.com/kthohr/gcem.git", "v1.17.0")
upstream_root = clone_repo("https://github.com/kthohr/gcem.git", "v1.18.0")
wpilib_root = get_repo_root()
wpimath = os.path.join(wpilib_root, "wpimath")

Expand Down
5 changes: 4 additions & 1 deletion wpimath/src/main/native/thirdparty/gcem/include/gcem.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down Expand Up @@ -35,6 +35,9 @@
#include "gcem_incl/sgn.hpp"

#include "gcem_incl/abs.hpp"
#include "gcem_incl/fabs.hpp"
#include "gcem_incl/fabsf.hpp"
#include "gcem_incl/fabsl.hpp"
#include "gcem_incl/ceil.hpp"
#include "gcem_incl/floor.hpp"
#include "gcem_incl/trunc.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down Expand Up @@ -31,7 +31,7 @@ namespace gcem
* Compile-time absolute value function
*
* @param x a real-valued input.
* @return the absolute value of \c x, \f$ |x| \f$.
* @return the absolute value of \c x, \f$ |x| \f$, where the return type is the same as the input type.
*/

template<typename T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
86 changes: 74 additions & 12 deletions wpimath/src/main/native/thirdparty/gcem/include/gcem_incl/atan.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down Expand Up @@ -43,21 +43,55 @@ namespace internal
template<typename T>
constexpr
T
atan_series_order_calc(const T x, const T x_pow, const uint_t order)
atan_series_order_calc(const T xx, const T x_pow, const uint_t order)
noexcept
{
return( T(1)/( T((order-1)*4 - 1) * x_pow ) \
- T(1)/( T((order-1)*4 + 1) * x_pow*x) );
- T(1)/( T((order-1)*4 + 1) * x_pow * xx) );
}

#if __cplusplus >= 201402L // C++14 version

template<typename T>
constexpr
T
atan_series_order(const T x, const T x_pow, const uint_t order_begin, const uint_t max_order)
noexcept
{
// run in reverse order to sum smallest numbers first

if (max_order == 1) {
return GCEM_HALF_PI - T(1)/x_pow; // use x_pow to avoid a warning
}

T xx = x*x;
T res = atan_series_order_calc(xx, pow(x,4*max_order-5), max_order);

uint_t depth = max_order - 1;

while (depth > order_begin) {
res += atan_series_order_calc(xx, pow(x,4*depth-5), depth);

--depth;
}

res += GCEM_HALF_PI - T(1)/x;

return res;
}

#else // C++11 version

template<typename T>
constexpr
T
atan_series_order(const T x, const T x_pow, const uint_t order, const uint_t max_order)
noexcept
{
return( order == 1 ? \
GCEM_HALF_PI - T(1)/x + atan_series_order(x*x,pow(x,3),order+1,max_order) :
return( max_order == 1 ? \
T(GCEM_HALF_PI) - T(1)/x :
order == 1 ? \
T(GCEM_HALF_PI) - T(1)/x + atan_series_order(x*x,pow(x,3),order+1,max_order) :
// NOTE: x changes to x*x for order > 1
order < max_order ? \
atan_series_order_calc(x,x_pow,order) \
Expand All @@ -66,6 +100,8 @@ noexcept
atan_series_order_calc(x,x_pow,order) );
}

#endif

template<typename T>
constexpr
T
Expand All @@ -85,6 +121,28 @@ noexcept

// CF

#if __cplusplus >= 201402L // C++14 version

template<typename T>
constexpr
T
atan_cf_recur(const T xx, const uint_t depth_begin, const uint_t max_depth)
noexcept
{
uint_t depth = max_depth - 1;
T res = T(2*(depth+1) - 1);

while (depth > depth_begin - 1) {
res = T(2*depth - 1) + T(depth*depth) * xx / res;

--depth;
}

return res;
}

#else // C++11 version

template<typename T>
constexpr
T
Expand All @@ -93,25 +151,27 @@ noexcept
{
return( depth < max_depth ? \
// if
T(2*depth - 1) + depth*depth*xx/atan_cf_recur(xx,depth+1,max_depth) :
T(2*depth - 1) + T(depth*depth) * xx / atan_cf_recur(xx,depth+1,max_depth) :
// else
T(2*depth - 1) );
}

#endif

template<typename T>
constexpr
T
atan_cf_main(const T x)
noexcept
{
return( x < T(0.5) ? x/atan_cf_recur(x*x,1U, 15U ) :
x < T(1) ? x/atan_cf_recur(x*x,1U, 25U ) :
x < T(1.5) ? x/atan_cf_recur(x*x,1U, 35U ) :
x < T(2) ? x/atan_cf_recur(x*x,1U, 45U ) :
x/atan_cf_recur(x*x,1U, 52U ) );
return( x < T(0.5) ? x/atan_cf_recur(x*x, 1U, 15U ) :
x < T(1) ? x/atan_cf_recur(x*x, 1U, 25U ) :
x < T(1.5) ? x/atan_cf_recur(x*x, 1U, 35U ) :
x < T(2) ? x/atan_cf_recur(x*x, 1U, 45U ) :
x/atan_cf_recur(x*x, 1U, 52U ) );
}

//
// choose between series expansion and continued fraction

template<typename T>
constexpr
Expand All @@ -122,6 +182,8 @@ noexcept
return( x > T(2.5) ? atan_series_main(x) : atan_cf_main(x) );
}

// check input

template<typename T>
constexpr
T
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down
56 changes: 52 additions & 4 deletions wpimath/src/main/native/thirdparty/gcem/include/gcem_incl/erf.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2023 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
Expand Down Expand Up @@ -37,6 +37,28 @@ namespace internal
// see
// http://functions.wolfram.com/GammaBetaErf/Erf/10/01/0007/

#if __cplusplus >= 201402L // C++14 version

template<typename T>
constexpr
T
erf_cf_large_recur(const T x, const int depth_end)
noexcept
{
int depth = GCEM_ERF_MAX_ITER - 1;
T res = x;

while (depth > depth_end - 1) {
res = x + 2 * depth / res;

--depth;
}

return res;
}

#else // C++11 version

template<typename T>
constexpr
T
Expand All @@ -45,11 +67,13 @@ noexcept
{
return( depth < GCEM_ERF_MAX_ITER ? \
// if
x + 2*depth/erf_cf_large_recur(x,depth+1) :
x + 2 * depth / erf_cf_large_recur(x,depth+1) :
// else
x );
}

#endif

template<typename T>
constexpr
T
Expand All @@ -63,6 +87,28 @@ noexcept
// see
// http://functions.wolfram.com/GammaBetaErf/Erf/10/01/0005/

#if __cplusplus >= 201402L // C++14 version

template<typename T>
constexpr
T
erf_cf_small_recur(const T xx, const int depth_end)
noexcept
{
int depth = GCEM_ERF_MAX_ITER - 1;
T res = T(2*(depth+1) - 1) - 2 * xx;

while (depth > depth_end - 1) {
res = T(2*depth - 1) - 2 * xx + 4 * depth * xx / res;

--depth;
}

return res;
}

#else // C++11 version

template<typename T>
constexpr
T
Expand All @@ -71,12 +117,14 @@ noexcept
{
return( depth < GCEM_ERF_MAX_ITER ? \
// if
(2*depth - T(1)) - 2*xx \
+ 4*depth*xx / erf_cf_small_recur(xx,depth+1) :
(2*depth - T(1)) - 2 * xx \
+ 4 * depth * xx / erf_cf_small_recur(xx,depth+1) :
// else
(2*depth - T(1)) - 2*xx );
}

#endif

template<typename T>
constexpr
T
Expand Down
Loading

0 comments on commit 1f92c59

Please sign in to comment.