Skip to content

Commit

Permalink
Using explicit sign function.
Browse files Browse the repository at this point in the history
  • Loading branch information
NicChr committed May 3, 2024
1 parent 90de63a commit c9abd4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/gcd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "cheapr_cpp.h"


template<typename T> 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;
Expand Down Expand Up @@ -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<double>(gcd);
break;
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/lag.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#include "cheapr_cpp.h"
#include <variant>
#include <memory>

template<typename T> 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
Expand Down

0 comments on commit c9abd4a

Please sign in to comment.