This repository has been archived on 2025-03-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cetra/lib/plugins/StandardLibrary/Math.js

61 lines
1.1 KiB
JavaScript
Raw Normal View History

function inc(val, options = [1]) {
let [name, amount = 1, ..._rest] = options;
return {
varName: name,
new: val * 1 + amount * 1,
old: val * 1,
};
}
function dec(val, options = [1]) {
let [name, amount = 1, ..._rest] = options;
return {
varName: name,
new: val * 1 - amount * 1,
old: val * 1,
};
}
function mult(val, options = [1]) {
let [name, amount = 1, ..._rest] = options;
return {
varName: name,
new: val * 1 * amount * 1,
old: val * 1,
};
}
function div(val, options = [1]) {
let [name, amount = 1, ..._rest] = options;
return {
varName: name,
new: ((val * 1) / amount) * 1,
old: val * 1,
};
}
function pow(val, options = [1]) {
let [name, amount = 1, ..._rest] = options;
return {
varName: name,
new: Math.pow(val * 1, amount * 1),
old: val * 1,
};
}
const BasicArithmetic = new Map([
['increment', inc],
['increase', inc],
['inc', inc],
['decrement', dec],
['decrease', dec],
['dec', dec],
['multiply', mult],
['mult', mult],
['divide', div],
['div', div],
['pow', pow],
]);
export default new Map([...BasicArithmetic.entries()]);