@hotmeshio/hotmesh
Version:
Permanent-Memory Workflows & AI Agents
185 lines (184 loc) • 4.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MathHandler = void 0;
class MathHandler {
add(...operands) {
// @ts-ignore
return operands.reduce((a, b) => {
if (Array.isArray(b)) {
return a + this.add(...b);
}
else {
return a + b;
}
}, 0);
}
subtract(...operands) {
if (operands.length === 0) {
throw new Error('At least one operand is required.');
}
let flatOperands = [];
operands.forEach((op) => {
if (Array.isArray(op)) {
flatOperands = [...flatOperands, ...op];
}
else {
flatOperands.push(op);
}
});
if (flatOperands.length === 0) {
throw new Error('At least one operand is required after flattening.');
}
const result = flatOperands.reduce((a, b, i) => {
return i === 0 ? a : a - b;
});
return result;
}
multiply(...operands) {
if (operands.length === 0) {
throw new Error('At least one operand is required.');
}
// @ts-ignore
return operands.reduce((a, b) => {
if (Array.isArray(b)) {
return a * this.multiply(...b);
}
else {
return a * b;
}
}, 1);
}
divide(...operands) {
if (operands.length === 0) {
throw new Error('At least one operand is required.');
}
let flatOperands = [];
operands.forEach((op) => {
if (Array.isArray(op)) {
flatOperands = [...flatOperands, ...op];
}
else {
flatOperands.push(op);
}
});
if (flatOperands.length === 0) {
throw new Error('At least one operand is required after flattening.');
}
const result = flatOperands.reduce((a, b, i) => {
if (b === 0) {
return NaN;
}
return i === 0 ? a : a / b;
});
if (isNaN(result)) {
return NaN;
}
return result;
}
abs(x) {
return Math.abs(x);
}
acos(x) {
return Math.acos(x);
}
acosh(x) {
return Math.acosh(x);
}
asin(x) {
return Math.asin(x);
}
asinh(x) {
return Math.asinh(x);
}
atan(x) {
return Math.atan(x);
}
atan2(y, x) {
return Math.atan2(y, x);
}
atanh(x) {
return Math.atanh(x);
}
cbrt(x) {
return Math.cbrt(x);
}
ceil(x) {
return Math.ceil(x);
}
clz32(x) {
return Math.clz32(x);
}
cos(x) {
return Math.cos(x);
}
cosh(x) {
return Math.cosh(x);
}
exp(x) {
return Math.exp(x);
}
expm1(x) {
return Math.expm1(x);
}
floor(x) {
return Math.floor(x);
}
fround(x) {
return Math.fround(x);
}
hypot(...values) {
return Math.hypot(...values);
}
imul(x, y) {
return Math.imul(x, y);
}
log(x) {
return Math.log(x);
}
log10(x) {
return Math.log10(x);
}
log1p(x) {
return Math.log1p(x);
}
log2(x) {
return Math.log2(x);
}
max(...values) {
return Math.max(...values);
}
min(...values) {
return Math.min(...values);
}
pow(x, y) {
return Math.pow(x, y);
}
random() {
return Math.random();
}
round(x) {
return Math.round(x);
}
sign(x) {
return Math.sign(x);
}
sin(x) {
return Math.sin(x);
}
sinh(x) {
return Math.sinh(x);
}
sqrt(x) {
return Math.sqrt(x);
}
tan(x) {
return Math.tan(x);
}
tanh(x) {
return Math.tanh(x);
}
trunc(x) {
return Math.trunc(x);
}
}
exports.MathHandler = MathHandler;