Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
New math function lcm(a,b): least common multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredwassermann committed Apr 18, 2018
1 parent 2dc65bc commit 8be6e44
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/math/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,28 @@ define(['jxg', 'utils/type'], function (JXG, Type) {
}
},

/**
* Least common multiple (lcm) of two numbers.
*
* @param {Number} a First number
* @param {Number} b Second number
* @returns {Number} lcm(a, b) if a and b are numbers, NaN else.
*/
lcm: function (a,b) {
var ret;

if (!(Type.isNumber(a) && Type.isNumber(b))) {
return NaN;
}

ret = a * b;
if (ret !== 0) {
return ret / this.gcd(a, b);
}

return 0;
},

/**
* Normalize the standard form [c, b0, b1, a, k, r, q0, q1].
* @private
Expand Down

0 comments on commit 8be6e44

Please sign in to comment.