algebra.js
Version:
Build, display, and solve algebraic equations.
70 lines (64 loc) • 1.07 kB
JavaScript
function gcd(x, y) {
while (y) {
var temp = x;
x = y;
y = temp % y;
}
return x;
}
function lcm(x, y) {
return (x * y) / gcd(x, y);
}
function isInt(thing) {
return (typeof thing == "number") && (thing % 1 === 0);
}
function round(decimal, places) {
places = (typeof(places) === "undefined" ? 2 : places);
var x = Math.pow(10, places);
return Math.round(parseFloat(decimal) * x) / x;
}
var GREEK_LETTERS = [
'alpha',
'beta',
'gamma',
'Gamma',
'delta',
'Delta',
'epsilon',
'varepsilon',
'zeta',
'eta',
'theta',
'vartheta',
'Theta',
'iota',
'kappa',
'lambda',
'Lambda',
'mu',
'nu',
'xi',
'Xi',
'pi',
'Pi',
'rho',
'varrho',
'sigma',
'Sigma',
'tau',
'upsilon',
'Upsilon',
'phi',
'varphi',
'Phi',
'chi',
'psi',
'Psi',
'omega',
'Omega'
];
exports.gcd = gcd;
exports.lcm = lcm;
exports.isInt = isInt;
exports.round = round;
exports.GREEK_LETTERS = GREEK_LETTERS;