mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[upstream_utils] Fix GCEM namespace usage and add hypot(x, y, z) (#6002)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
135
upstream_utils/gcem_patches/0002-Add-hypot-x-y-z.patch
Normal file
135
upstream_utils/gcem_patches/0002-Add-hypot-x-y-z.patch
Normal file
@@ -0,0 +1,135 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Sun, 3 Dec 2023 14:03:58 -0800
|
||||
Subject: [PATCH 2/2] Add hypot(x, y, z)
|
||||
|
||||
---
|
||||
include/gcem_incl/hypot.hpp | 85 +++++++++++++++++++++++++++++++++++--
|
||||
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
|
||||
--- a/include/gcem_incl/hypot.hpp
|
||||
+++ b/include/gcem_incl/hypot.hpp
|
||||
@@ -27,6 +27,7 @@
|
||||
#ifndef _gcem_hypot_HPP
|
||||
#define _gcem_hypot_HPP
|
||||
|
||||
+#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
@@ -39,10 +40,29 @@ namespace internal
|
||||
template<typename T>
|
||||
constexpr
|
||||
T
|
||||
-hypot_compute(const T x, const T ydx)
|
||||
+hypot_compute(const T x, const T y)
|
||||
noexcept
|
||||
{
|
||||
- return abs(x) * sqrt( T(1) + (ydx * ydx) );
|
||||
+ T a = std::max(abs(x), abs(y));
|
||||
+ if (a) {
|
||||
+ return a * sqrt((x / a) * (x / a) + (y / a) * (y / a));
|
||||
+ } else {
|
||||
+ return {};
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+template<typename T>
|
||||
+constexpr
|
||||
+T
|
||||
+hypot_compute(const T x, const T y, const T z)
|
||||
+noexcept
|
||||
+{
|
||||
+ T a = std::max({abs(x), abs(y), abs(z)});
|
||||
+ if (a) {
|
||||
+ return a * sqrt((x / a) * (x / a) + (y / a) * (y / a) + (z / a) * (z / a));
|
||||
+ } else {
|
||||
+ return {};
|
||||
+ }
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -62,7 +82,35 @@ noexcept
|
||||
GCLIM<T>::min() > abs(y) ? \
|
||||
abs(x) :
|
||||
// else
|
||||
- hypot_compute(x, y/x) );
|
||||
+ hypot_compute(x, y) );
|
||||
+}
|
||||
+
|
||||
+template<typename T>
|
||||
+constexpr
|
||||
+T
|
||||
+hypot_vals_check(const T x, const T y, const T z)
|
||||
+noexcept
|
||||
+{
|
||||
+ return( any_nan(x, y, z) ? \
|
||||
+ GCLIM<T>::quiet_NaN() :
|
||||
+ //
|
||||
+ any_inf(x,y,z) ? \
|
||||
+ GCLIM<T>::infinity() :
|
||||
+ // indistinguishable from zero or one
|
||||
+ GCLIM<T>::min() > abs(x) && GCLIM<T>::min() > abs(y) ? \
|
||||
+ abs(z) :
|
||||
+ GCLIM<T>::min() > abs(x) && GCLIM<T>::min() > abs(z) ? \
|
||||
+ abs(y) :
|
||||
+ GCLIM<T>::min() > abs(y) && GCLIM<T>::min() > abs(z) ? \
|
||||
+ abs(x) :
|
||||
+ GCLIM<T>::min() > abs(x) ? \
|
||||
+ hypot_vals_check(y, z) :
|
||||
+ GCLIM<T>::min() > abs(y) ? \
|
||||
+ hypot_vals_check(x, z) :
|
||||
+ GCLIM<T>::min() > abs(z) ? \
|
||||
+ hypot_vals_check(x, y) :
|
||||
+ // else
|
||||
+ hypot_compute(x, y, z) );
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename TC = common_return_t<T1,T2>>
|
||||
@@ -74,6 +122,15 @@ noexcept
|
||||
return hypot_vals_check(static_cast<TC>(x),static_cast<TC>(y));
|
||||
}
|
||||
|
||||
+template<typename T1, typename T2, typename T3, typename TC = common_return_t<T1,T2,T3>>
|
||||
+constexpr
|
||||
+TC
|
||||
+hypot_type_check(const T1 x, const T2 y, const T3 z)
|
||||
+noexcept
|
||||
+{
|
||||
+ return hypot_vals_check(static_cast<TC>(x),static_cast<TC>(y),static_cast<TC>(z));
|
||||
+}
|
||||
+
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,6 +154,28 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
+/**
|
||||
+ * Compile-time Pythagorean addition function
|
||||
+ *
|
||||
+ * @param x a real-valued input.
|
||||
+ * @param y a real-valued input.
|
||||
+ * @param z a real-valued input.
|
||||
+ * @return Computes \f$ x \oplus y \oplus z = \sqrt{x^2 + y^2 + z^2} \f$.
|
||||
+ */
|
||||
+
|
||||
+template<typename T1, typename T2, typename T3>
|
||||
+constexpr
|
||||
+common_return_t<T1,T2,T3>
|
||||
+hypot(const T1 x, const T2 y, const T3 z)
|
||||
+noexcept
|
||||
+{
|
||||
+ if (std::is_constant_evaluated()) {
|
||||
+ return internal::hypot_type_check(x,y,z);
|
||||
+ } else {
|
||||
+ return std::hypot(x, y, z);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -19,7 +19,10 @@ def main():
|
||||
|
||||
# Apply patches to upstream Git repo
|
||||
os.chdir(upstream_root)
|
||||
for f in ["0001-Call-std-functions-if-not-constant-evaluated.patch"]:
|
||||
for f in [
|
||||
"0001-Call-std-functions-if-not-constant-evaluated.patch",
|
||||
"0002-Add-hypot-x-y-z.patch",
|
||||
]:
|
||||
git_am(os.path.join(wpilib_root, "upstream_utils/gcem_patches", f))
|
||||
|
||||
# Delete old install
|
||||
|
||||
@@ -23,82 +23,79 @@
|
||||
|
||||
#include "gcem_incl/gcem_options.hpp"
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
#include "gcem_incl/quadrature/gauss_legendre_50.hpp"
|
||||
#include "gcem_incl/quadrature/gauss_legendre_50.hpp"
|
||||
|
||||
#include "gcem_incl/is_inf.hpp"
|
||||
#include "gcem_incl/is_nan.hpp"
|
||||
#include "gcem_incl/is_finite.hpp"
|
||||
|
||||
#include "gcem_incl/signbit.hpp"
|
||||
#include "gcem_incl/copysign.hpp"
|
||||
#include "gcem_incl/neg_zero.hpp"
|
||||
#include "gcem_incl/sgn.hpp"
|
||||
#include "gcem_incl/is_inf.hpp"
|
||||
#include "gcem_incl/is_nan.hpp"
|
||||
#include "gcem_incl/is_finite.hpp"
|
||||
|
||||
#include "gcem_incl/abs.hpp"
|
||||
#include "gcem_incl/ceil.hpp"
|
||||
#include "gcem_incl/floor.hpp"
|
||||
#include "gcem_incl/trunc.hpp"
|
||||
#include "gcem_incl/is_odd.hpp"
|
||||
#include "gcem_incl/is_even.hpp"
|
||||
#include "gcem_incl/max.hpp"
|
||||
#include "gcem_incl/min.hpp"
|
||||
#include "gcem_incl/sqrt.hpp"
|
||||
#include "gcem_incl/inv_sqrt.hpp"
|
||||
#include "gcem_incl/hypot.hpp"
|
||||
#include "gcem_incl/signbit.hpp"
|
||||
#include "gcem_incl/copysign.hpp"
|
||||
#include "gcem_incl/neg_zero.hpp"
|
||||
#include "gcem_incl/sgn.hpp"
|
||||
|
||||
#include "gcem_incl/find_exponent.hpp"
|
||||
#include "gcem_incl/find_fraction.hpp"
|
||||
#include "gcem_incl/find_whole.hpp"
|
||||
#include "gcem_incl/mantissa.hpp"
|
||||
#include "gcem_incl/round.hpp"
|
||||
#include "gcem_incl/fmod.hpp"
|
||||
#include "gcem_incl/abs.hpp"
|
||||
#include "gcem_incl/ceil.hpp"
|
||||
#include "gcem_incl/floor.hpp"
|
||||
#include "gcem_incl/trunc.hpp"
|
||||
#include "gcem_incl/is_odd.hpp"
|
||||
#include "gcem_incl/is_even.hpp"
|
||||
#include "gcem_incl/max.hpp"
|
||||
#include "gcem_incl/min.hpp"
|
||||
#include "gcem_incl/sqrt.hpp"
|
||||
#include "gcem_incl/inv_sqrt.hpp"
|
||||
#include "gcem_incl/hypot.hpp"
|
||||
|
||||
#include "gcem_incl/pow_integral.hpp"
|
||||
#include "gcem_incl/exp.hpp"
|
||||
#include "gcem_incl/expm1.hpp"
|
||||
#include "gcem_incl/log.hpp"
|
||||
#include "gcem_incl/log1p.hpp"
|
||||
#include "gcem_incl/log2.hpp"
|
||||
#include "gcem_incl/log10.hpp"
|
||||
#include "gcem_incl/pow.hpp"
|
||||
#include "gcem_incl/find_exponent.hpp"
|
||||
#include "gcem_incl/find_fraction.hpp"
|
||||
#include "gcem_incl/find_whole.hpp"
|
||||
#include "gcem_incl/mantissa.hpp"
|
||||
#include "gcem_incl/round.hpp"
|
||||
#include "gcem_incl/fmod.hpp"
|
||||
|
||||
#include "gcem_incl/gcd.hpp"
|
||||
#include "gcem_incl/lcm.hpp"
|
||||
#include "gcem_incl/pow_integral.hpp"
|
||||
#include "gcem_incl/exp.hpp"
|
||||
#include "gcem_incl/expm1.hpp"
|
||||
#include "gcem_incl/log.hpp"
|
||||
#include "gcem_incl/log1p.hpp"
|
||||
#include "gcem_incl/log2.hpp"
|
||||
#include "gcem_incl/log10.hpp"
|
||||
#include "gcem_incl/pow.hpp"
|
||||
|
||||
#include "gcem_incl/tan.hpp"
|
||||
#include "gcem_incl/cos.hpp"
|
||||
#include "gcem_incl/sin.hpp"
|
||||
#include "gcem_incl/gcd.hpp"
|
||||
#include "gcem_incl/lcm.hpp"
|
||||
|
||||
#include "gcem_incl/atan.hpp"
|
||||
#include "gcem_incl/atan2.hpp"
|
||||
#include "gcem_incl/acos.hpp"
|
||||
#include "gcem_incl/asin.hpp"
|
||||
#include "gcem_incl/tan.hpp"
|
||||
#include "gcem_incl/cos.hpp"
|
||||
#include "gcem_incl/sin.hpp"
|
||||
|
||||
#include "gcem_incl/tanh.hpp"
|
||||
#include "gcem_incl/cosh.hpp"
|
||||
#include "gcem_incl/sinh.hpp"
|
||||
#include "gcem_incl/atan.hpp"
|
||||
#include "gcem_incl/atan2.hpp"
|
||||
#include "gcem_incl/acos.hpp"
|
||||
#include "gcem_incl/asin.hpp"
|
||||
|
||||
#include "gcem_incl/atanh.hpp"
|
||||
#include "gcem_incl/acosh.hpp"
|
||||
#include "gcem_incl/asinh.hpp"
|
||||
#include "gcem_incl/tanh.hpp"
|
||||
#include "gcem_incl/cosh.hpp"
|
||||
#include "gcem_incl/sinh.hpp"
|
||||
|
||||
#include "gcem_incl/binomial_coef.hpp"
|
||||
#include "gcem_incl/lgamma.hpp"
|
||||
#include "gcem_incl/tgamma.hpp"
|
||||
#include "gcem_incl/factorial.hpp"
|
||||
#include "gcem_incl/lbeta.hpp"
|
||||
#include "gcem_incl/beta.hpp"
|
||||
#include "gcem_incl/lmgamma.hpp"
|
||||
#include "gcem_incl/log_binomial_coef.hpp"
|
||||
#include "gcem_incl/atanh.hpp"
|
||||
#include "gcem_incl/acosh.hpp"
|
||||
#include "gcem_incl/asinh.hpp"
|
||||
|
||||
#include "gcem_incl/erf.hpp"
|
||||
#include "gcem_incl/erf_inv.hpp"
|
||||
#include "gcem_incl/incomplete_beta.hpp"
|
||||
#include "gcem_incl/incomplete_beta_inv.hpp"
|
||||
#include "gcem_incl/incomplete_gamma.hpp"
|
||||
#include "gcem_incl/incomplete_gamma_inv.hpp"
|
||||
}
|
||||
#include "gcem_incl/binomial_coef.hpp"
|
||||
#include "gcem_incl/lgamma.hpp"
|
||||
#include "gcem_incl/tgamma.hpp"
|
||||
#include "gcem_incl/factorial.hpp"
|
||||
#include "gcem_incl/lbeta.hpp"
|
||||
#include "gcem_incl/beta.hpp"
|
||||
#include "gcem_incl/lmgamma.hpp"
|
||||
#include "gcem_incl/log_binomial_coef.hpp"
|
||||
|
||||
#include "gcem_incl/erf.hpp"
|
||||
#include "gcem_incl/erf_inv.hpp"
|
||||
#include "gcem_incl/incomplete_beta.hpp"
|
||||
#include "gcem_incl/incomplete_beta_inv.hpp"
|
||||
#include "gcem_incl/incomplete_gamma.hpp"
|
||||
#include "gcem_incl/incomplete_gamma_inv.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
/**
|
||||
* Compile-time absolute value function
|
||||
*
|
||||
@@ -49,4 +52,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -88,4 +91,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -72,4 +75,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -86,4 +89,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -69,5 +72,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -159,4 +162,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -92,4 +95,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -83,4 +86,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
/**
|
||||
* Compile-time beta function
|
||||
*
|
||||
@@ -50,4 +53,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#ifndef _gcem_binomial_coef_HPP
|
||||
#define _gcem_binomial_coef_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -88,4 +91,6 @@ noexcept
|
||||
return internal::binomial_coef_type_check(n,k);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -134,4 +137,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
/**
|
||||
* Compile-time copy sign function
|
||||
*
|
||||
@@ -45,4 +48,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -87,4 +90,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -69,4 +72,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -147,4 +150,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#ifndef _gcem_erf_inv_HPP
|
||||
#define _gcem_erf_inv_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -260,5 +263,6 @@ noexcept
|
||||
return internal::erf_inv_begin( static_cast<return_t<T>>(p) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -134,4 +137,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -80,4 +83,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_factorial_HPP
|
||||
#define _gcem_factorial_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -95,4 +98,6 @@ noexcept
|
||||
return internal::factorial_recur(x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_find_exponent_HPP
|
||||
#define _gcem_find_exponent_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -54,4 +57,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_find_fraction_HPP
|
||||
#define _gcem_find_fraction_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -43,4 +46,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_find_whole_HPP
|
||||
#define _gcem_find_whole_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -43,4 +46,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -134,4 +137,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -74,4 +77,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#ifndef _gcem_gcd_HPP
|
||||
#define _gcem_gcd_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -79,4 +82,6 @@ noexcept
|
||||
return internal::gcd_type_check(a,b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,19 +27,42 @@
|
||||
#ifndef _gcem_hypot_HPP
|
||||
#define _gcem_hypot_HPP
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
constexpr
|
||||
T
|
||||
hypot_compute(const T x, const T ydx)
|
||||
hypot_compute(const T x, const T y)
|
||||
noexcept
|
||||
{
|
||||
return abs(x) * sqrt( T(1) + (ydx * ydx) );
|
||||
T a = std::max(abs(x), abs(y));
|
||||
if (a) {
|
||||
return a * sqrt((x / a) * (x / a) + (y / a) * (y / a));
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr
|
||||
T
|
||||
hypot_compute(const T x, const T y, const T z)
|
||||
noexcept
|
||||
{
|
||||
T a = std::max({abs(x), abs(y), abs(z)});
|
||||
if (a) {
|
||||
return a * sqrt((x / a) * (x / a) + (y / a) * (y / a) + (z / a) * (z / a));
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -59,7 +82,35 @@ noexcept
|
||||
GCLIM<T>::min() > abs(y) ? \
|
||||
abs(x) :
|
||||
// else
|
||||
hypot_compute(x, y/x) );
|
||||
hypot_compute(x, y) );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr
|
||||
T
|
||||
hypot_vals_check(const T x, const T y, const T z)
|
||||
noexcept
|
||||
{
|
||||
return( any_nan(x, y, z) ? \
|
||||
GCLIM<T>::quiet_NaN() :
|
||||
//
|
||||
any_inf(x,y,z) ? \
|
||||
GCLIM<T>::infinity() :
|
||||
// indistinguishable from zero or one
|
||||
GCLIM<T>::min() > abs(x) && GCLIM<T>::min() > abs(y) ? \
|
||||
abs(z) :
|
||||
GCLIM<T>::min() > abs(x) && GCLIM<T>::min() > abs(z) ? \
|
||||
abs(y) :
|
||||
GCLIM<T>::min() > abs(y) && GCLIM<T>::min() > abs(z) ? \
|
||||
abs(x) :
|
||||
GCLIM<T>::min() > abs(x) ? \
|
||||
hypot_vals_check(y, z) :
|
||||
GCLIM<T>::min() > abs(y) ? \
|
||||
hypot_vals_check(x, z) :
|
||||
GCLIM<T>::min() > abs(z) ? \
|
||||
hypot_vals_check(x, y) :
|
||||
// else
|
||||
hypot_compute(x, y, z) );
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename TC = common_return_t<T1,T2>>
|
||||
@@ -71,6 +122,15 @@ noexcept
|
||||
return hypot_vals_check(static_cast<TC>(x),static_cast<TC>(y));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename TC = common_return_t<T1,T2,T3>>
|
||||
constexpr
|
||||
TC
|
||||
hypot_type_check(const T1 x, const T2 y, const T3 z)
|
||||
noexcept
|
||||
{
|
||||
return hypot_vals_check(static_cast<TC>(x),static_cast<TC>(y),static_cast<TC>(z));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,4 +154,28 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile-time Pythagorean addition function
|
||||
*
|
||||
* @param x a real-valued input.
|
||||
* @param y a real-valued input.
|
||||
* @param z a real-valued input.
|
||||
* @return Computes \f$ x \oplus y \oplus z = \sqrt{x^2 + y^2 + z^2} \f$.
|
||||
*/
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
constexpr
|
||||
common_return_t<T1,T2,T3>
|
||||
hypot(const T1 x, const T2 y, const T3 z)
|
||||
noexcept
|
||||
{
|
||||
if (std::is_constant_evaluated()) {
|
||||
return internal::hypot_type_check(x,y,z);
|
||||
} else {
|
||||
return std::hypot(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
#ifndef _gcem_incomplete_beta_HPP
|
||||
#define _gcem_incomplete_beta_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -191,4 +194,6 @@ noexcept
|
||||
return internal::incomplete_beta_type_check(a,b,z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_incomplete_beta_inv_HPP
|
||||
#define _gcem_incomplete_beta_inv_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -349,4 +352,6 @@ noexcept
|
||||
return internal::incomplete_beta_inv_type_check(a,b,p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_incomplete_gamma_HPP
|
||||
#define _gcem_incomplete_gamma_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -244,4 +247,6 @@ noexcept
|
||||
return internal::incomplete_gamma_type_check(a,x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_incomplete_gamma_inv_HPP
|
||||
#define _gcem_incomplete_gamma_inv_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -268,4 +271,6 @@ noexcept
|
||||
return internal::incomplete_gamma_inv_type_check(a,p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_inv_sqrt_HPP
|
||||
#define _gcem_inv_sqrt_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -85,4 +88,6 @@ noexcept
|
||||
return internal::inv_sqrt_check( static_cast<return_t<T>>(x) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_is_even_HPP
|
||||
#define _gcem_is_even_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -38,4 +41,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_is_finite_HPP
|
||||
#define _gcem_is_finite_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -75,4 +78,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_is_inf_HPP
|
||||
#define _gcem_is_inf_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -169,4 +172,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_is_nan_HPP
|
||||
#define _gcem_is_nan_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -77,4 +80,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_is_odd_HPP
|
||||
#define _gcem_is_odd_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -39,4 +42,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#ifndef _gcem_lbeta_HPP
|
||||
#define _gcem_lbeta_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
/**
|
||||
* Compile-time log-beta function
|
||||
*
|
||||
@@ -39,4 +42,6 @@ noexcept
|
||||
return( (lgamma(a) + lgamma(b)) - lgamma(a+b) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#ifndef _gcem_lcm_HPP
|
||||
#define _gcem_lcm_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -62,4 +65,6 @@ noexcept
|
||||
return internal::lcm_type_check(a,b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -139,4 +142,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_lmgamma_HPP
|
||||
#define _gcem_lmgamma_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -70,4 +73,6 @@ noexcept
|
||||
return internal::lmgamma_recur(static_cast<return_t<T1>>(a),p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -190,4 +193,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -63,4 +66,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -84,4 +87,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -63,4 +66,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#ifndef _gcem_log_binomial_coef_HPP
|
||||
#define _gcem_log_binomial_coef_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -62,4 +65,6 @@ noexcept
|
||||
return internal::log_binomial_coef_type_check(n,k);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_mantissa_HPP
|
||||
#define _gcem_mantissa_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -44,4 +47,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
/**
|
||||
* Compile-time pairwise maximum function
|
||||
*
|
||||
@@ -45,4 +48,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
/**
|
||||
* Compile-time pairwise minimum function
|
||||
*
|
||||
@@ -45,4 +48,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
* extract signbit for signed zeros
|
||||
*/
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -35,3 +38,5 @@ noexcept
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -86,4 +89,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _gcem_pow_integral_HPP
|
||||
#define _gcem_pow_integral_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -125,4 +128,6 @@ noexcept
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
* Gauss-Legendre quadrature: 30 points
|
||||
*/
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
static const long double gauss_legendre_30_points[30] = \
|
||||
{
|
||||
-0.05147184255531769583302521316672L,
|
||||
@@ -89,3 +92,5 @@ static const long double gauss_legendre_30_weights[30] = \
|
||||
0.00796819249616660561546588347467L,
|
||||
0.00796819249616660561546588347467L\
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
* Gauss-Legendre quadrature: 50 points
|
||||
*/
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
static const long double gauss_legendre_50_points[50] = \
|
||||
{
|
||||
-0.03109833832718887611232898966595L,
|
||||
@@ -129,3 +132,5 @@ static const long double gauss_legendre_50_weights[50] = \
|
||||
0.00290862255315514095840072434286L,
|
||||
0.00290862255315514095840072434286L\
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -129,4 +132,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#ifndef _gcem_sgn_HPP
|
||||
#define _gcem_sgn_HPP
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
/**
|
||||
* Compile-time sign function
|
||||
*
|
||||
@@ -42,4 +45,6 @@ noexcept
|
||||
0 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
/**
|
||||
* Compile-time sign bit detection function
|
||||
*
|
||||
@@ -48,4 +51,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -89,4 +92,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -69,4 +72,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -113,4 +116,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -144,4 +147,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -93,4 +96,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -84,4 +87,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
namespace gcem
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
@@ -125,4 +128,6 @@ noexcept
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user