1/** math-expression-evaluator version 1.3.8 2 Dated:2021-07-03 */ 3 4(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.mexp = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 5var Mexp=require('./postfix_evaluator.js'); 6Mexp.prototype.formulaEval = function () { 7 "use strict"; 8 var stack=[],pop1,pop2,pop3; 9 var disp=[]; 10 var temp=''; 11 var arr=this.value; 12 for(var i=0;i<arr.length;i++){ 13 if(arr[i].type===1||arr[i].type===3){ 14 disp.push({value:arr[i].type===3?arr[i].show:arr[i].value,type:1}); 15 } 16 else if(arr[i].type===13){ 17 disp.push({value:arr[i].show,type:1}); 18 } 19 else if(arr[i].type===0){ 20 disp[disp.length-1]={value:arr[i].show+(arr[i].show!="-"?"(":"")+disp[disp.length-1].value+(arr[i].show!="-"?")":""),type:0}; 21 } 22 else if(arr[i].type===7){ 23 disp[disp.length-1]={value:(disp[disp.length-1].type!=1?"(":"")+disp[disp.length-1].value+(disp[disp.length-1].type!=1?")":"")+arr[i].show,type:7}; 24 } 25 else if(arr[i].type===10){ 26 pop1=disp.pop(); 27 pop2=disp.pop(); 28 if(arr[i].show==='P'||arr[i].show==='C')disp.push({value:"<sup>"+pop2.value+"</sup>"+arr[i].show+"<sub>"+pop1.value+"</sub>",type:10}); 29 else disp.push({value:(pop2.type!=1?"(":"")+pop2.value+(pop2.type!=1?")":"")+"<sup>"+pop1.value+"</sup>",type:1}); 30 } 31 else if(arr[i].type===2||arr[i].type===9){ 32 pop1=disp.pop(); 33 pop2=disp.pop(); 34 disp.push({value:(pop2.type!=1?"(":"")+pop2.value+(pop2.type!=1?")":"")+arr[i].show+(pop1.type!=1?"(":"")+pop1.value+(pop1.type!=1?")":""),type:arr[i].type}); 35 } 36 else if(arr[i].type===12){ 37 pop1=disp.pop(); 38 pop2=disp.pop(); 39 pop3=disp.pop(); 40 disp.push({value:arr[i].show+"("+pop3.value+","+pop2.value+","+pop1.value+")",type:12}); 41 } 42 } 43 return disp[0].value; 44}; 45module.exports=Mexp; 46},{"./postfix_evaluator.js":5}],2:[function(require,module,exports){ 47'use strict' 48var Mexp = require('./math_function.js') 49function inc (arr, val) { 50 for (var i = 0; i < arr.length; i++) { 51 arr[i] += val 52 } 53 return arr 54} 55var token = [ 56 'sin', 57 'cos', 58 'tan', 59 'pi', 60 '(', 61 ')', 62 'P', 63 'C', 64 ' ', 65 'asin', 66 'acos', 67 'atan', 68 '7', 69 '8', 70 '9', 71 'int', 72 'cosh', 73 'acosh', 74 'ln', 75 '^', 76 'root', 77 '4', 78 '5', 79 '6', 80 '/', 81 '!', 82 'tanh', 83 'atanh', 84 'Mod', 85 '1', 86 '2', 87 '3', 88 '*', 89 'sinh', 90 'asinh', 91 'e', 92 'log', 93 '0', 94 '.', 95 '+', 96 '-', 97 ',', 98 'Sigma', 99 'n', 100 'Pi', 101 'pow', 102 'floor' 103] 104var show = [ 105 'sin', 106 'cos', 107 'tan', 108 'π', 109 '(', 110 ')', 111 'P', 112 'C', 113 ' ', 114 'asin', 115 'acos', 116 'atan', 117 '7', 118 '8', 119 '9', 120 'Int', 121 'cosh', 122 'acosh', 123 ' ln', 124 '^', 125 'root', 126 '4', 127 '5', 128 '6', 129 '÷', 130 '!', 131 'tanh', 132 'atanh', 133 ' Mod ', 134 '1', 135 '2', 136 '3', 137 '×', 138 'sinh', 139 'asinh', 140 'e', 141 ' log', 142 '0', 143 '.', 144 '+', 145 '-', 146 ',', 147 'Σ', 148 'n', 149 'Π', 150 'pow', 151 'floor' 152] 153var eva = [ 154 Mexp.math.sin, 155 Mexp.math.cos, 156 Mexp.math.tan, 157 'PI', 158 '(', 159 ')', 160 Mexp.math.P, 161 Mexp.math.C, 162 ' '.anchor, 163 Mexp.math.asin, 164 Mexp.math.acos, 165 Mexp.math.atan, 166 '7', 167 '8', 168 '9', 169 Math.floor, 170 Mexp.math.cosh, 171 Mexp.math.acosh, 172 Math.log, 173 Math.pow, 174 Math.sqrt, 175 '4', 176 '5', 177 '6', 178 Mexp.math.div, 179 Mexp.math.fact, 180 Mexp.math.tanh, 181 Mexp.math.atanh, 182 Mexp.math.mod, 183 '1', 184 '2', 185 '3', 186 Mexp.math.mul, 187 Mexp.math.sinh, 188 Mexp.math.asinh, 189 'E', 190 Mexp.math.log, 191 '0', 192 '.', 193 Mexp.math.add, 194 Mexp.math.sub, 195 ',', 196 Mexp.math.sigma, 197 'n', 198 Mexp.math.Pi, 199 Math.pow, 200 Math.floor 201] 202var preced = { 203 0: 11, 204 1: 0, 205 2: 3, 206 3: 0, 207 4: 0, 208 5: 0, 209 6: 0, 210 7: 11, 211 8: 11, 212 9: 1, 213 10: 10, 214 11: 0, 215 12: 11, 216 13: 0, 217 14: -1 // will be filtered after lexer 218} // stores precedence by types 219var type = [ 220 0, 0, 0, 3, 4, 5, 10, 10, 14, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 10, 0, 1, 1, 1, 2, 7, 0, 0, 2, 1, 1, 221 1, 2, 0, 0, 3, 0, 1, 6, 9, 9, 11, 12, 13, 12, 8 222] 223/* 2240 : function with syntax function_name(Maths_exp) 2251 : numbers 2262 : binary operators like * / Mod left associate and same precedence 2273 : Math constant values like e,pi,Cruncher ans 2284 : opening bracket 2295 : closing bracket 2306 : decimal 2317 : function with syntax (Math_exp)function_name 2328: function with syntax function_name(Math_exp1,Math_exp2) 2339 : binary operator like +,- 23410: binary operator like P C or ^ 23511: , 23612: function with , seperated three parameters and third parameter is a string that will be mexp string 23713: variable of Sigma function 238*/ 239var type0 = { 240 0: true, 241 1: true, 242 3: true, 243 4: true, 244 6: true, 245 8: true, 246 9: true, 247 12: true, 248 13: true, 249 14: true 250} // type2:true,type4:true,type9:true,type11:true,type21:true,type22 251var type1 = { 252 0: true, 253 1: true, 254 2: true, 255 3: true, 256 4: true, 257 5: true, 258 6: true, 259 7: true, 260 8: true, 261 9: true, 262 10: true, 263 11: true, 264 12: true, 265 13: true 266} // type3:true,type5:true,type7:true,type23 267var type1Asterick = { 268 0: true, 269 3: true, 270 4: true, 271 8: true, 272 12: true, 273 13: true 274} 275var empty = {} 276var type3Asterick = { 277 0: true, 278 1: true, 279 3: true, 280 4: true, 281 6: true, 282 8: true, 283 12: true, 284 13: true 285} // type_5:true,type_7:true,type_23 286var type6 = { 287 1: true 288} 289var newAr = [ 290 [], 291 [ 292 '1', 293 '2', 294 '3', 295 '7', 296 '8', 297 '9',
298 '4', 299 '5', 300 '6', 301 '+', 302 '-', 303 '*', 304 '/', 305 '(', 306 ')', 307 '^', 308 '!', 309 'P', 310 'C', 311 'e', 312 '0', 313 '.', 314 ',', 315 'n', 316 ' ' 317 ], 318 ['pi', 'ln', 'Pi'], 319 ['sin', 'cos', 'tan', 'Del', 'int', 'Mod', 'log', 'pow'], 320 ['asin', 'acos', 'atan', 'cosh', 'root', 'tanh', 'sinh'], 321 ['acosh', 'atanh', 'asinh', 'Sigma','floor'] 322] 323 324function match (str1, str2, i, x) { 325 for (var f = 0; f < x; f++) { 326 if (str1[i + f] !== str2[f]) { 327 return false 328 } 329 } 330 return true 331} 332Mexp.addToken = function (tokens) { 333 for (var i = 0; i < tokens.length; i++) { 334 var x = tokens[i].token.length 335 var temp = -1 336 337 // newAr is a specially designed data structure index of 1d array = length of tokens 338 newAr[x] = newAr[x] || [] 339 for (var y = 0; y < newAr[x].length; y++) { 340 if (tokens[i].token === newAr[x][y]) { 341 temp = token.indexOf(newAr[x][y]) 342 break 343 } 344 } 345 if (temp === -1) { 346 token.push(tokens[i].token) 347 type.push(tokens[i].type) 348 if (newAr.length <= tokens[i].token.length) { 349 newAr[tokens[i].token.length] = [] 350 } 351 newAr[tokens[i].token.length].push(tokens[i].token) 352 eva.push(tokens[i].value) 353 show.push(tokens[i].show) 354 } else { 355 // overwrite 356 token[temp] = tokens[i].token 357 type[temp] = tokens[i].type 358 eva[temp] = tokens[i].value 359 show[temp] = tokens[i].show 360 } 361 } 362} 363 364function tokenize (string) { 365 var nodes = [] 366 var length = string.length 367 var key, x, y 368 for (var i = 0; i < length; i++) { 369 if (i < length - 1 && string[i] === ' ' && string[i + 1] === ' ') { 370 continue 371 } 372 key = '' 373 for ( 374 x = string.length - i > newAr.length - 2 ? newAr.length - 1 : string.length - i; 375 x > 0; 376 x-- 377 ) { 378 if (newAr[x] === undefined) continue 379 for (y = 0; y < newAr[x].length; y++) { 380 381 if (match(string, newAr[x][y], i, x)) { 382 key = newAr[x][y] 383 384 y = newAr[x].length 385 x = 0 386 } 387 } 388 } 389 i += key.length - 1 390 391 if (key === '') { 392 throw new Mexp.Exception("Can't understand after " + string.slice(i)) 393 } 394 var index = token.indexOf(key) 395 396 nodes.push({ 397 index: index, 398 token: key, 399 type: type[index], 400 eval: eva[index], 401 precedence: preced[type[index]], 402 show: show[index] 403 }) 404 } 405 return nodes 406} 407 408Mexp.lex = function (inp, tokens) { 409 'use strict' 410 411 var changeSignObj = { 412 value: Mexp.math.changeSign, 413 type: 0, 414 pre: 21, 415 show: '-' 416 } 417 var closingParObj = { 418 value: ')', 419 show: ')', 420 type: 5, 421 pre: 0 422 } 423 var openingParObj = { 424 value: '(', 425 type: 4, 426 pre: 0, 427 show: '(' 428 } 429 var str = [openingParObj] 430 431 var ptc = [] // Parenthesis to close at the beginning is after one token 432 var inpStr = inp 433 var allowed = type0 434 var bracToClose = 0 435 var asterick = empty 436 var prevKey = '' 437 var i 438 if (typeof tokens !== 'undefined') { 439 Mexp.addToken(tokens) 440 } 441 var obj = {} 442 var nodes = tokenize(inpStr) 443 for (i = 0; i < nodes.length; i++) { 444 var node = nodes[i] 445 if (node.type === 14) { 446 if ( 447 i > 0 && 448 i < nodes.length - 1 && 449 nodes[i + 1].type === 1 && 450 (nodes[i - 1].type === 1 || nodes[i - 1].type === 6) 451 ) { throw new Mexp.Exception('Unexpected Space') } 452 continue 453 } 454 var cToken = node.token 455 var cType = node.type 456 var cEv = node.eval 457 var cPre = node.precedence 458 var cShow = node.show 459 var pre = str[str.length - 1] 460 var j 461 for (j = ptc.length; j--;) { 462 // loop over ptc 463 if (ptc[j] === 0) { 464 if ([0, 2, 3, 4, 5, 9, 11, 12, 13].indexOf(cType) !== -1) { 465 if (allowed[cType] !== true) { 466 throw new Mexp.Exception(cToken + ' is not allowed after ' + prevKey) 467 } 468 str.push(closingParObj) 469 allowed = type1 470 asterick = type3Asterick 471 inc(ptc, -1).pop() 472 } 473 } else break 474 } 475 //console.log(allowed ); 476 //console.log(nodes ); 477 if (allowed[cType] !== true) { 478 throw new Mexp.Exception(cToken + ' is not allowed after ' + prevKey) 479 } 480 if (asterick[cType] === true) { 481 cType = 2 482 cEv = Mexp.math.mul 483 cShow = '×' 484 cPre = 3
485 i = i - 1 486 } 487 obj = { 488 value: cEv, 489 type: cType, 490 pre: cPre, 491 show: cShow 492 } 493 if (cType === 0) { 494 allowed = type0 495 asterick = empty 496 inc(ptc, 2).push(2) 497 str.push(obj) 498 str.push(openingParObj) 499 } else if (cType === 1) { 500 if (pre.type === 1) { 501 pre.value += cEv 502 inc(ptc, 1) 503 } else { 504 str.push(obj) 505 } 506 allowed = type1 507 asterick = type1Asterick 508 } else if (cType === 2) { 509 allowed = type0 510 asterick = empty 511 inc(ptc, 2) 512 str.push(obj) 513 } else if (cType === 3) { 514 // constant 515 str.push(obj) 516 allowed = type1 517 asterick = type3Asterick 518 } else if (cType === 4) { 519 inc(ptc, 1) 520 bracToClose++ 521 allowed = type0 522 asterick = empty 523 str.push(obj) 524 } else if (cType === 5) { 525 if (!bracToClose) { 526 throw new Mexp.Exception('Closing parenthesis are more than opening one, wait What!!!') 527 } 528 bracToClose-- 529 allowed = type1 530 asterick = type3Asterick 531 str.push(obj) 532 inc(ptc, 1) 533 } else if (cType === 6) { 534 if (pre.hasDec) { 535 throw new Mexp.Exception('Two decimals are not allowed in one number') 536 } 537 if (pre.type !== 1) { 538 pre = { 539 value: 0, 540 type: 1, 541 pre: 0 542 } // pre needs to be changed as it will the last value now to be safe in later code 543 str.push(pre) 544 inc(ptc, -1) 545 } 546 allowed = type6 547 inc(ptc, 1) 548 asterick = empty 549 pre.value += cEv 550 pre.hasDec = true 551 } else if (cType === 7) { 552 allowed = type1 553 asterick = type3Asterick 554 inc(ptc, 1) 555 str.push(obj) 556 } 557 if (cType === 8) { 558 allowed = type0 559 asterick = empty 560 inc(ptc, 4).push(4) 561 str.push(obj) 562 str.push(openingParObj) 563 } else if (cType === 9) { 564 if (pre.type === 9) { 565 if (pre.value === Mexp.math.add) { 566 pre.value = cEv 567 pre.show = cShow 568 inc(ptc, 1) 569 } else if (pre.value === Mexp.math.sub && cShow === '-') { 570 pre.value = Mexp.math.add 571 pre.show = '+' 572 inc(ptc, 1) 573 } 574 } else if ( 575 pre.type !== 5 && 576 pre.type !== 7 && 577 pre.type !== 1 && 578 pre.type !== 3 && 579 pre.type !== 13 580 ) { 581 // changesign only when negative is found 582 if (cToken === '-') { 583 // do nothing for + token 584 // don't add with the above if statement as that will run the else statement of parent if on Ctoken + 585 allowed = type0 586 asterick = empty 587 inc(ptc, 2).push(2) 588 str.push(changeSignObj) 589 str.push(openingParObj) 590 } 591 } else { 592 str.push(obj) 593 inc(ptc, 2) 594 } 595 allowed = type0 596 asterick = empty 597 } else if (cType === 10) { 598 allowed = type0 599 asterick = empty 600 inc(ptc, 2) 601 str.push(obj) 602 } else if (cType === 11) { 603 allowed = type0 604 asterick = empty 605 str.push(obj) 606 } else if (cType === 12) { 607 allowed = type0 608 asterick = empty 609 inc(ptc, 6).push(6) 610 str.push(obj) 611 str.push(openingParObj) 612 } else if (cType === 13) { 613 allowed = type1 614 asterick = type3Asterick 615 str.push(obj) 616 } 617 inc(ptc, -1) 618 prevKey = cToken 619 } 620 for (j = ptc.length; j--;) { 621 // loop over ptc 622 if (ptc[j] === 0) { 623 str.push(closingParObj) 624 inc(ptc, -1).pop() 625 } else break // if it is not zero so before ptc also cant be zero 626 } 627 if (allowed[5] !== true) { 628 throw new Mexp.Exception('complete the expression') 629 } 630 while (bracToClose--) { 631 str.push(closingParObj) 632 } 633 634 str.push(closingParObj) 635 // console.log(str); 636 return new Mexp(str) 637} 638module.exports = Mexp 639 640},{"./math_function.js":3}],3:[function(require,module,exports){ 641"use strict"; 642var Mexp = function (parsed) { 643 this.value = parsed 644} 645 646Mexp.math = { 647 isDegree: true, // mode of calculator 648 acos: function (x) { 649 return (Mexp.math.isDegree ? 180 / Math.PI * Math.acos(x) : Math.acos(x)) 650 }, 651 add: function (a, b) { 652 return a + b 653 }, 654 asin: function (x) { 655 return (Mexp.math.isDegree ? 180 / Math.PI * Math.asin(x) : Math.asin(x)) 656 }, 657 atan: function (x) { 658 return (Mexp.math.isDegree ? 180 / Math.PI * Math.atan(x) : Math.atan(x)) 659 }, 660 acosh: function (x) { 661 return Math.log(x + Math.sqrt(x * x - 1)) 662 }, 663 asinh: function (x) { 664 return Math.log(x + Math.sqrt(x * x + 1)) 665 }, 666 atanh: function (x) { 667 return Math.log((1 + x) / (1 - x)) 668 }, 669 C: function (n, r) { 670 var pro = 1 671 var other = n - r 672 var choice = r 673 if (choice < other) { 674 choice = other 675 other = r 676 } 677 for (var i = choice + 1; i <= n; i++) { 678 pro *= i 679 } 680 return pro / Mexp.math.fact(other) 681 }, 682 changeSign: function (x) { 683 return -x 684 }, 685 cos: function (x) { 686 if (Mexp.math.isDegree) x = Mexp.math.toRadian(x) 687 return Math.cos(x) 688 }, 689 cosh: function (x) { 690 return (Math.pow(Math.E, x) + Math.pow(Math.E, -1 * x)) / 2 691 }, 692 div: function (a, b) { 693 return a / b 694 }, 695 fact: function (n) { 696 if (n % 1 !== 0) return 'NaN' 697 var pro = 1 698 for (var i = 2; i <= n; i++) { 699 pro *= i 700 } 701 return pro 702 }, 703 inverse: function (x) { 704 return 1 / x 705 }, 706 log: function (i) { 707 return Math.log(i) / Math.log(10) 708 }, 709 mod: function (a, b) { 710 return a % b 711 }, 712 mul: function (a, b) { 713 return a * b 714 }, 715 P: function (n, r) { 716 var pro = 1 717 for (var i = Math.floor(n) - Math.floor(r) + 1; i <= Math.floor(n); i++) { 718 pro *= i 719 } 720 return pro 721 }, 722 Pi: function (low, high, ex) { 723 var pro = 1 724 for (var i = low; i <= high; i++) { 725 pro *= Number(ex.postfixEval({ 726 n: i 727 })) 728 } 729 return pro 730 }, 731 pow10x: function (e) { 732 var x = 1 733 while (e--) { 734 x *= 10 735 } 736 return x 737 }, 738 sigma: function (low, high, ex) { 739 var sum = 0 740 for (var i = low; i <= high; i++) { 741 sum += Number(ex.postfixEval({ 742 n: i 743 })) 744 } 745 return sum 746 }, 747 sin: function (x) { 748 if (Mexp.math.isDegree) x = Mexp.math.toRadian(x) 749 return Math.sin(x) 750 }, 751 sinh: function (x) { 752 return (Math.pow(Math.E, x) - Math.pow(Math.E, -1 * x)) / 2 753 }, 754 sub: function (a, b) { 755 return a - b 756 }, 757 tan: function (x) { 758 if (Mexp.math.isDegree) x = Mexp.math.toRadian(x) 759 return Math.tan(x) 760 }, 761 tanh: function (x) { 762 return Mexp.sinha(x) / Mexp.cosha(x) 763 }, 764 toRadian: function (x) { 765 return x * Math.PI / 180 766 } 767} 768Mexp.Exception = function (message) { 769 this.message = message 770} 771module.exports = Mexp 772 773},{}],4:[function(require,module,exports){ 774 775var Mexp = require('./lexer.js'); 776 777Mexp.prototype.toPostfix = function () { 778 'use strict'; 779 var post = [], elem, popped, prep, pre, ele; 780 var stack = [{ value: "(", type: 4, pre: 0 }]; 781 var arr = this.value; 782 for (var i = 1; i < arr.length; i++) { 783 if (arr[i].type === 1 || arr[i].type === 3 || arr[i].type === 13) { //if token is number,constant,or n(which is also a special constant in our
783case) 784 if (arr[i].type === 1) 785 arr[i].value = Number(arr[i].value); 786 post.push(arr[i]); 787 } 788 else if (arr[i].type === 4) { 789 stack.push(arr[i]); 790 } 791 else if (arr[i].type === 5) { 792 while ((popped = stack.pop()).type !== 4) { 793 post.push(popped); 794 } 795 } 796 else if (arr[i].type === 11) { 797 while ((popped = stack.pop()).type !== 4) { 798 post.push(popped); 799 } 800 stack.push(popped); 801 } 802 else { 803 elem = arr[i]; 804 pre = elem.pre; 805 ele = stack[stack.length - 1]; 806 prep = ele.pre; 807 var flag = ele.value == 'Math.pow' && elem.value == 'Math.pow'; 808 if (pre > prep) stack.push(elem); 809 else { 810 while (prep >= pre && !flag || flag && pre < prep) { 811 popped = stack.pop(); 812 ele = stack[stack.length - 1]; 813 post.push(popped); 814 prep = ele.pre; 815 flag = elem.value == 'Math.pow' && ele.value == 'Math.pow'; 816 } 817 stack.push(elem); 818 } 819 } 820 } 821 return new Mexp(post); 822}; 823module.exports = Mexp; 824},{"./lexer.js":2}],5:[function(require,module,exports){ 825var Mexp=require('./postfix.js'); 826Mexp.prototype.postfixEval = function (UserDefined) { 827 'use strict'; 828 UserDefined=UserDefined||{}; 829 UserDefined.PI=Math.PI; 830 UserDefined.E=Math.E; 831 var stack=[],pop1,pop2,pop3; 832 var disp=[]; 833 var temp=''; 834 var arr=this.value; 835 var bool=(typeof UserDefined.n!=="undefined"); 836 for(var i=0;i<arr.length;i++){ 837 if(arr[i].type===1){ 838 stack.push({value:arr[i].value,type:1}); 839 } 840 else if(arr[i].type===3){ 841 stack.push({value:UserDefined[arr[i].value],type:1}); 842 } 843 else if(arr[i].type===0){ 844 if(typeof stack[stack.length-1].type==="undefined"){ 845 stack[stack.length-1].value.push(arr[i]); 846 } 847 else stack[stack.length-1].value=arr[i].value(stack[stack.length-1].value); 848 } 849 else if(arr[i].type===7){ 850 if(typeof stack[stack.length-1].type==="undefined"){ 851 stack[stack.length-1].value.push(arr[i]); 852 } 853 else stack[stack.length-1].value=arr[i].value(stack[stack.length-1].value); 854 } 855 else if(arr[i].type===8){
856 pop1=stack.pop(); 857 pop2=stack.pop(); 858 stack.push({type:1,value:arr[i].value(pop2.value,pop1.value)}); 859 } 860 else if(arr[i].type===10){ 861 pop1=stack.pop(); 862 pop2=stack.pop(); 863 if(typeof pop2.type==="undefined"){ 864 pop2.value=pop2.concat(pop1); 865 pop2.value.push(arr[i]); 866 stack.push(pop2); 867 } 868 else if (typeof pop1.type==="undefined") { 869 pop1.unshift(pop2); 870 pop1.push(arr[i]); 871 stack.push(pop1); 872 } 873 else{ 874 stack.push({type:1,value:arr[i].value(pop2.value,pop1.value)}); 875 } 876 } 877 else if(arr[i].type===2||arr[i].type===9){ 878 pop1=stack.pop(); 879 pop2=stack.pop(); 880 if(typeof pop2.type==="undefined"){ 881 pop2=pop2.concat(pop1); 882 pop2.push(arr[i]); 883 stack.push(pop2); 884 } 885 else if (typeof pop1.type==="undefined") { 886 pop1.unshift(pop2); 887 pop1.push(arr[i]); 888 stack.push(pop1); 889 } 890 else{ 891 stack.push({type:1,value:arr[i].value(pop2.value,pop1.value)}); 892 } 893 } 894 else if(arr[i].type===12){ 895 pop1=stack.pop(); 896 if (typeof pop1.type!=="undefined") { 897 pop1=[pop1]; 898 } 899 pop2=stack.pop(); 900 pop3=stack.pop(); 901 stack.push({type:1,value:arr[i].value(pop3.value,pop2.value,new Mexp(pop1))}); 902 } 903 else if(arr[i].type===13){ 904 if(bool){ 905 stack.push({value:UserDefined[arr[i].value],type:3}); 906 } 907 else stack.push([arr[i]]); 908 } 909 } 910 if (stack.length>1) { 911 throw(new Mexp.Exception("Uncaught Syntax error")); 912 } 913 return stack[0].value>1000000000000000?"Infinity":parseFloat(stack[0].value.toFixed(15)); 914}; 915Mexp.eval=function(str,tokens,obj){ 916 if (typeof tokens==="undefined") { 917 return this.lex(str).toPostfix().postfixEval(); 918 } 919 else if (typeof obj==="undefined") { 920 if (typeof tokens.length!=="undefined") 921 return this.lex(str,tokens).toPostfix().postfixEval(); 922 else 923 return this.lex(str).toPostfix().postfixEval(tokens); 924 } 925 else 926 return this.lex(str,tokens).toPostfix().postfixEval(obj); 927}; 928module.exports=Mexp; 929},{"./postfix.js":4}]},{},[1])(1) 930});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.