Skip to content

Commit

Permalink
Fix adaptive expressions divide function (#3528)
Browse files Browse the repository at this point in the history
* fix division + add tests

* let -> const

Co-authored-by: Steven Gum <14935595+stevengum@users.noreply.github.com>
Co-authored-by: Hongyang Du (hond) <hond@microsoft.com>
  • Loading branch information
3 people authored Apr 7, 2021
1 parent c6b01e3 commit b5feba0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export class Divide extends MultivariateNumericEvaluator {
* @private
*/
private static func(args: any[]): number {
return Math.floor(Number(args[0]) / Number(args[1]));
const result: number = Number(args[0]) / Number(args[1]);
if (Number.isInteger(args[0]) && Number.isInteger(args[1])) {
return Math.floor(result);
}
return result;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions libraries/adaptive-expressions/tests/expressionParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const testCases = [
['1 *\r\n 2 + 3', 5],
['1 + 2 * 3', 7],
['4 / 2', 2],
['11.2 / 2', 5.6],
['4 /\r\n 2', 2],
['1 + 3 / 2', 2],
['(1 + 3) / 2', 2],
Expand Down Expand Up @@ -483,6 +484,7 @@ const testCases = [
['div(mul(2, 5), 2)', 5],
['div(5, 2)', 2],
['div(5, 2, 2)', 1],
['div(11.2, 2)', 5.6],
['exp(2,2)', 4.0],
['mod(5,2)', 1],
['rand(1, 2)', 1],
Expand Down

0 comments on commit b5feba0

Please sign in to comment.