Skip to content

Commit

Permalink
fixes #1661
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 4, 2024
1 parent 2a9e64b commit 7bcd528
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/arith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void operator%(std::vector<double>& a, const std::vector<double>& b) {
if (std::isnan(a[i]) || std::isnan(b[i])) {
a[i] = NAN;
} else {
a[i] = std::fmod(a[i], b[i]);
a[i] = std::abs(std::fmod(a[i], b[i]));
}
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ SpatRaster SpatRaster::arith(SpatRaster x, std::string oper, bool falseNA, SpatO
a % b;
} else if (oper == "%/%") {
for (size_t i=0; i<a.size(); i++) {
a[i] = trunc(a[i] / b[i]);
a[i] = floor(a[i] / b[i]);
}
} else if (oper == "==") {
for (size_t i=0; i<a.size(); i++) {
Expand Down Expand Up @@ -336,18 +336,18 @@ SpatRaster SpatRaster::arith(double x, std::string oper, bool reverse, bool fals
} else if (oper == "%") {
if (reverse) {
for (size_t i=0; i<a.size(); i++) {
a[i] = std::fmod(x, a[i]);
a[i] = std::abs(std::fmod(x, a[i]));
}
} else {
for (size_t i=0; i<a.size(); i++) {
a[i] = std::fmod(a[i], x);
a[i] = std::abs(std::fmod(a[i], x));
}
}
} else if (oper == "%/%") {
if (reverse) {
for (double& d : a) d = trunc(x / d);
for (double& d : a) d = floor(x / d);
} else {
for (double& d : a) d = trunc(d / x);
for (double& d : a) d = floor(d / x);
}
} else if (oper == "==") {
for (double& d : a) if (!std::isnan(d)) d = d == x;
Expand Down

0 comments on commit 7bcd528

Please sign in to comment.