Skip to content

Commit

Permalink
BigDecimal modulus impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 30, 2021
1 parent a31b619 commit 0ec8768
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -1894,7 +1894,14 @@ else if (CoreUtilities.toLowerCase(element).contains(CoreUtilities.toLowerCase(c
attribute.echoError("Element '" + object + "' is not a valid decimal number!");
return null;
}
return new ElementTag(object.asDouble() % attribute.getDoubleContext(1));
try {
// Note: "remainder" method has doc "Note that this is not the modulo operation (the result can be negative)."
// however this doc is misleading - standard modulo with "%" allows negatives in the exact same situation (first parameter is negative).
return new ElementTag(object.asBigDecimal().remainder(object.getBD(attribute.getContext(1))));
}
catch (Throwable e) {
return new ElementTag(object.asDouble() % attribute.getDoubleContext(1));
}
};
registerTag("mod", modRunnable);
registerTag("%", modRunnable);
Expand Down

0 comments on commit 0ec8768

Please sign in to comment.