mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
38 lines (37 loc) • 1.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isConstantExpression = isConstantExpression;
Object.defineProperty(exports, "isConstantNode", {
enumerable: true,
get: function get() {
return _is.isConstantNode;
}
});
exports.isNumericNode = isNumericNode;
Object.defineProperty(exports, "isVariableNode", {
enumerable: true,
get: function get() {
return _is.isSymbolNode;
}
});
var _is = require("../../../utils/is.js");
function isNumericNode(x) {
return (0, _is.isConstantNode)(x) || (0, _is.isOperatorNode)(x) && x.isUnary() && (0, _is.isConstantNode)(x.args[0]);
}
function isConstantExpression(x) {
if ((0, _is.isConstantNode)(x)) {
// Basic Constant types
return true;
}
if (((0, _is.isFunctionNode)(x) || (0, _is.isOperatorNode)(x)) && x.args.every(isConstantExpression)) {
// Can be constant depending on arguments
return true;
}
if ((0, _is.isParenthesisNode)(x) && isConstantExpression(x.content)) {
// Parenthesis are transparent
return true;
}
return false; // Probably missing some edge cases
}
;