Source: Red Hat ( Matteo Mortari)
The spec defines "modulo" FEEL built-in function as: "the remainder of the division of dividend by divisor"
However, this might be subject to ambiguity in the case the Divisor or Dividend are negative, as also mentioned by Wikipedia page which list examples out of several programming languages and systems: https://en.wikipedia.org/wiki/Modulo_operation by saying that "When either a or n is negative, the naive definition breaks down and programming languages differ in how these values are defined".
FEEL aims to be a Friendly Enough expression language, and especially thinking about DMN practitioners who might be used to Spreadsheet based systems might find misleading if the definition of the FEEL "modulo" gets bind to the Java (default) definition, the following table illustrate the difference:
Dividend Divisor MOD() from Microsoft Excel, Google Sheets, LibreOffice Calc, Wolfram Alpha, etc. Java % or BigDecimal#remainder or other languages default 10 4 2 2 10 -4 -2 2 -10 4 2 -2 -10 -4 -2 -2
or to other implementation languages where the definition of Modulo/Remainder is not explicit, or the default one is not consistent with Spreadsheet default one.
It is proposed therefore to change the specification in 10.3.4.5 Numeric functions Table 70 for the FEEL "modulo" built-in function
FROM: "Returns the remainder of the division of dividend by divisor."
TO: "Returns the remainder of the division of dividend by divisor. In case either dividend or divisor is negative, the result has the same sign of the dividend."
This would avoid ambiguity by making a clear definition of what should be the sign in case either of the operands are negative.
This should make this consistent with Spreadsheet based system result of "MOD()" expression, which should address being Friendly Enough for DMN practitioners and DM analyst.
This would not make the result the same as the default of Java % operator or BigDecimal#remainder, but Java based implementation/Vendor can trivially address the result to be compliant with the spec.
Reported: DMN 1.2b1 — Fri, 4 Jan 2019 18:34 GMT
Disposition: Duplicate or Merged — DMN 1.3
corrected in dmn13-125
corrected in dmn13-125
Updated: Mon, 30 Mar 2020 19:50 GMT