nerdamer-ts
Version:
javascript light-weight symbolic math expression evaluator
42 lines • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cbrt = void 0;
const Symbol_1 = require("../../../Types/Symbol");
const Utils_1 = require("../../../Core/Utils");
const index_1 = require("../index");
const Groups_1 = require("../../../Types/Groups");
const Parser_1 = require("../../../Parser/Parser");
/**
* The cube root function
* @param {Symbol} symbol
* @returns {Symbol}
*/
function cbrt(symbol) {
if (!symbol.isConstant(true)) {
var retval;
var n = symbol.power / 3;
//take the cube root of the multplier
var m = (0, index_1.pow)((0, Parser_1.parse)(symbol.multiplier), new Symbol_1.Symbol(1 / 3));
//strip the multiplier
var sym = symbol.toUnitMultiplier();
//simplify the power
if ((0, Utils_1.isInt)(n)) {
retval = (0, index_1.pow)(sym.toLinear(), (0, Parser_1.parse)(n));
}
else {
if (sym.group === Groups_1.Groups.CB) {
retval = new Symbol_1.Symbol(1);
sym.each(function (x) {
retval = (0, index_1.multiply)(retval, cbrt(x));
});
}
else {
retval = (0, Symbol_1.symfunction)('cbrt', [sym]);
}
}
return (0, index_1.multiply)(m, retval);
}
return (0, index_1.nthroot)(symbol, new Symbol_1.Symbol(3));
}
exports.cbrt = cbrt;
//# sourceMappingURL=cbrt.js.map