7fa21f90d038c5059cef5f093cb95f8bf70cce60ff2bb14926a2cd568c1278b8cb105ad7d1c3b3b591ba08a4a2a0aa7a055663d8f40beb0b4c9b3f66563d44 23 KB

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