How to use the eval function from mathjs
Find comprehensive JavaScript mathjs.eval code examples handpicked from public code repositorys.
GitHub: DextApp/dext
2 3 4 5 6 7 8 9 10 11
const math = require('mathjs'); module.exports = { action: 'copy', query: query => { try { const ans = math.eval(query); if (typeof ans === 'function') { throw new Error('function returned'); } const items = [];
68
721
25
+ 9 other calls in file
27 28 29 30 31 32 33 34 35 36
* - originalSize * - ratio * @return {[type]} [description] */ function getSizeFromRatio(options) { var ratio = math.eval(options.ratio); return Math.floor(options.size * ratio); } function executeResize(options, callback) {
20
84
12
+ 13 other calls in file
GitHub: lin-xin/calculator
58 59 60 61 62 63 64 65 66 67
clickOperat(ope, event) { const _this = this, res = document.querySelector('.result-text'); switch (ope) { case '+/-': res.innerHTML = result = math.eval(result + '*-1'); _this.resize(); _this.isEqual ? _this.flag = true : ''; break; case '%':
15
58
3
+ 47 other calls in file
GitHub: Mitorisia/Komugari
24 25 26 27 28 29 30 31 32 33
} run(message, args) { var { equation } = args; try { var solution = math.eval(equation) } catch (err) { return message.channel.send(`❎ | I couldn\'t solve that equation! \`${err}\``) }
44
40
6
+ 7 other calls in file
GitHub: librewiki/liberty-engine
6 7 8 9 10 11 12 13 14 15
'#expr': new MagicWord( '#expr', true, (parsingData, [expression = '']) => { try { return math.eval(expression); } catch (e) { return `<span class="error"> ${e} </span>`; } },
9
42
5
+ 7 other calls in file
15 16 17 18 19 20 21 22 23 24
/** * @param: eval_string * @param: x * return: */ var f = (eval_string, x) => math.eval(eval_string, { x: x }); /** * @param: eval_string * @param: x
0
11
2
+ 13 other calls in file
GitHub: fudgepop01/Floofy-Bot
25 26 27 28 29 30 31 32 33 34
async run(msg, args) { // eslint-disable-line consistent-return let out = `${msg.author} asked \` ${args.query}\`\n`; try { return msg.say(out + math.eval(args.query)); } catch (err) { msg.channel.startTyping(); wolfram.query(args.query, (error, results) => { if (error) {
0
2
1
+ 13 other calls in file
GitHub: Fermium/mathlion
45 46 47 48 49 50 51 52 53 54
Prevent various problems with numbers formatting */ var vectoreq = equation.split('*').join('.*').split('/').join('./').split('^').join('.^'); vectoreq = vectoreq.split('..*').join('.*').split('../').join('./').split('..^').join('.^'); //check if eachseries is being elaborated var evaluated = math.eval(vectoreq,scope);//evaluate the new value/function in the scope /* Dealing with mathjs result cases: 1) With ResultSet results it gets the entries[0] array which is the actual elaboration 2) Converting Unit objects to their value in said measure
23
77
11
+ 5 other calls in file
164 165 166 167 168 169 170 171 172 173
*/ function getMatrix(evalAsMath) { if (evalAsMath){ row0 = [ mathjs.eval($('#matrix-row-0-col-0').val()), mathjs.eval($('#matrix-row-0-col-1').val()), mathjs.eval($('#matrix-row-0-col-2').val()), ]; row1 = [
75
0
0
+ 35 other calls in file
GitHub: mljs/calculus
2 3 4 5 6 7 8 9 10 11
var math = require('mathjs'); describe('Numerical methods', function() { describe('Integrate', function () { var f = math.eval('f(x) = 2 + sin(2 * sqrt(x))'); it('Simpson rule', function () { var result = Integrals.integrate(f, 1, 6, 5, "simpson"); result.should.be.approximately(8.18301550, 10e-8);
0
1
13
+ 13 other calls in file
GitHub: klendi/subiex
2 3 4 5 6 7 8 9 10 11
const math = require('mathjs') Subiex.registerCommand('math', 'default', (message, bot) => { let result try { result = math.eval(message.content) } catch (error) { console.log('Failed math calculation ' + message.content + '\nError: ' + e.stack) return 'Error while evaluating the math expression.' } finally {
11
20
2
GitHub: DasWolke/yuki
47 48 49 50 51 52 53 54 55
let result; try { // noinspection JSUnresolvedFunction result = MathJS.eval(args); } catch (e) { result = e; }
2
0
2
+ 5 other calls in file
45 46 47 48 49 50 51 52 53 54
var radiusW = 0; while (time > 0) { radiusW += math.eval([`t=${time}`, equation])[1]; time -= inc; } var yw = radiusW * Math.cos(Wheading * Math.PI / 180); // y component of vector of wind
1
3
14
GitHub: ellis/roboliq
159 160 161 162 163 164 165 166 167 168
assert(_.isArray(calibratorData0), "expected calibratorData to be an array"); const calibratorData = _.sortBy(calibratorData0, calibratorVariable); const dataLE = _.last(_.filter(calibratorData, x => x[calibratorVariable] <= targetValue)); const dataGE = _.first(_.filter(calibratorData, x => x[calibratorVariable] >= targetValue)); const valueLE = math.eval(dataLE[calibratorVariable]); const valueGE = math.eval(dataGE[calibratorVariable]); const volumeLE = math.eval(dataLE.volume); const volumeGE = math.eval(dataGE.volume); if (math.equal(valueLE, targetValue)) { item.volume = volumeLE;
0
9
3
+ 9 other calls in file
GitHub: bloc97/DiscordChatBot
222 223 224 225 226 227 228 229 230 231
let y; if (nexty) { y = nexty; } else { mathjs.eval("x="+i, scope); y = mathjs.eval(fx, scope); } // if (y > (ysize/zoom)/2 || y < -(ysize/zoom)/2) { //too conservative // continue;
0
1
0
+ 15 other calls in file
120 121 122 123 124 125 126 127 128 129
throw new Error('Dir must be \'left\', \'middle\' or \'right\''); try { point = math.bignumber(point); if (dir === 'middle' || dir === 'mid') { let s1 = math.eval(expression.toString(), { x: point.sub(SMALL_NUMBER) }); let s2 = math.eval(expression.toString(), { x: point.add(SMALL_NUMBER) }); if (math.abs(s1.sub(s2)).greaterThan(math.EPSILON)) throw new Error(`Limit does not converge from both sides: x<sup>-</sup> = ${s1.toExponential()} while x<sup>+</sup> = ${s2.toExponential()}`);
0
0
5
+ 69 other calls in file
mathjs.evaluate is the most popular function in mathjs (87200 examples)