diff --git a/src/gcd.cpp b/src/gcd.cpp index 46a515c..1b8d997 100644 --- a/src/gcd.cpp +++ b/src/gcd.cpp @@ -1,5 +1,10 @@ #include "cheapr_cpp.h" + +template T cpp_sign(T x) { + return (x > 0) - (x < 0); +} + [[cpp11::register]] double cpp_gcd2(double x, double y, double tol, bool na_rm){ double zero = 0.0; @@ -127,7 +132,7 @@ SEXP cpp_gcd(SEXP x, double tol, bool na_rm, bool break_early, bool round){ break; } if (break_early && agcd > 0.0 && agcd < (tol + tol)){ - gcd = tol * ( (gcd > 0) - (gcd < 0)); // tol * sign(gcd) + gcd = tol * cpp_sign(gcd); break; } } diff --git a/src/lag.cpp b/src/lag.cpp index 578825d..748d22c 100644 --- a/src/lag.cpp +++ b/src/lag.cpp @@ -1,10 +1,4 @@ #include "cheapr_cpp.h" -#include -#include - -template T cpp_sign(T x) { - return (x > 0) - (x < 0); -} // Internal fast check for valid order values (here they are 0-indexed) // Where rng = length(x) - 1