"use strict";
/*!
 Based on ndef.parser, by Raphael Graf(r@undefined.ch)
 http://www.undefined.ch/mparser/index.html

 Ported to JavaScript and modified by Matthew Crumley (email@matthewcrumley.com, http://silentmatt.com/)
 Released under the MIT license.

 Modified again by Gong Dahan (gdh1995@qq.com), in order to support Vimium C and add functions and operators.

 You are free to use and modify this code in anyway you find useful. Please leave this comment in the code
 to acknowledge its original source. If you feel like it, I enjoy hearing about projects that use my code,
 but don't feel like you have to let me know or ask permission.
*/(function(){function t(t,i,s,h){this.t=t,this.i=i||0,this.s=s||0,this.h=h!==void 0&&h!==null?h:0}function i(t,i){this.r=t,this.e=i.e,this.n=i.n,this.a=i.a}function s(t,i){for(var s,h=i.split(/\./),r=t;s=h.shift();){if(!(s in r))return!1;r=r[s]}return!0}function h(t,i){for(var s,h=i.split(/\./),r=t;s=h.shift();)r=r[s];return r}function r(t,i){return Number(t)+Number(i)}function e(t,i){return t-i}function n(t,i){return t*i}function a(t,i){return t/i}function u(t,i){return(t|0)/(i|0)|0}function o(t,i){return t%i}function f(t,i){return""+t+i}function c(t,i){return t===i}function l(t,i){return t!==i}function M(t,i){return t>i}function _(t,i){return t<i}function p(t,i){return t>=i}function d(t,i){return t<=i}function b(t,i){return t&i}function v(t,i){return t|i}function w(t,i){return t^i}function k(t,i){return t<<i}function m(t,i){return t>>i}function x(t,i){return t>>>i}function g(t,i){return t&&i}function y(t,i){return t||i}function E(t){return Math.sinh?Math.sinh(t):(Math.exp(t)-Math.exp(-t))/2}function j(t){return Math.cosh?Math.cosh(t):(Math.exp(t)+Math.exp(-t))/2}function I(t){return Math.tanh?Math.tanh(t):t===1/0?1:t===-1/0?-1:(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t))}function O(t){return Math.asinh?Math.asinh(t):t===-1/0?t:Math.log(t+Math.sqrt(t*t+1))}function q(t){return Math.acosh?Math.acosh(t):Math.log(t+Math.sqrt(t*t-1))}function C(t){return Math.atanh?Math.atanh(t):Math.log((1+t)/(1-t))/2}function N(t){return Math.log(t)*Math.LOG10E}function P(t){return-t}function S(t){return!t}function A(t){return~t}function T(t){return Math.random()*(t||1)}function F(t){for(var i=t=Math.floor(t);t>1;)i*=--t;return i}function L(t,i,s){return t?i:s}function R(t,i){return{}.toString.call(t)!="[object Array]"?[t,i]:((t=t.slice()).push(i),t)}function MathParser(){this.success=!1,this.errormsg="",this.u="",this.o=0,this.f=0,this.c=0,this.l=0,this.M=0,this.e={__proto__:null,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:E,cosh:j,tanh:I,asinh:O,acosh:q,atanh:C,sqrt:Math.sqrt,log:Math.log,lg:N,log10:N,abs:Math.abs,ceil:Math.ceil,floor:Math.floor,round:Math.round,trunc:V,"-":P,"!":S,"~":A,not:S,exp:Math.exp},this.n={__proto__:null,"+":r,"-":e,"*":n,"/":a,":":a,"\\":u,"%":o,"**":Math.pow,"&":b,"|":v,"^":w,"&&":g,"||":y,",":R,";":f,"==":c,"!=":l,"<":_,"<<":k,"<=":d,">":M,">=":p,">>":m,">>>":x,and:g,or:y},this.a={__proto__:null,random:T,fac:F,min:Math.min,max:Math.max,hypot:W,pyt:W,pow:Math.pow,atan2:Math.atan2,if:L},this.consts={__proto__:null,E:Math.E,PI:Math.PI}}var V,W;i.prototype={constructor:i,evaluate(t){var i,r,e,n,a,u,o,f;for(t=t||{},i=[],a=this.r.length,o=0;o<a;o++)if((f=(u=this.r[o]).t)===0)i.push(u.h);else if(f===2)e=i.pop(),r=i.pop(),i.push((n=this.n[u.i])(r,e));else if(f===3)if(s(t,u.i))i.push(h(t,u.i));else{if(!s(this.a,u.i))throw new Error("undefined variable: "+u.i);i.push(h(this.a,u.i))}else if(f===1)r=i.pop(),i.push((n=this.e[u.i])(r));else{if(f!==4)throw new Error("invalid Expression");if(r=i.pop(),!(n=i.pop()).apply||!n.call)throw new Error(n+" is not a function");({}).toString.call(r)=="[object Array]"?i.push(n.apply(void 0,r)):i.push(n.call(void 0,r))}if(i.length>1)throw new Error("invalid Expression (parity)");return i[0]}},V=Math.trunc||(t=>t<0?Math.ceil(t):Math.floor(t)),W=Math.hypot||function(){var t,i,s=0,h=arguments.length;for(t=0;t<h;t++){if(i=arguments[t],(i*=i)==1/0)return i;s+=i}return Math.sqrt(s)},MathParser.u=i,MathParser.prototype={constructor:MathParser,p(s){var h,r,e,n,a,u=[],o=[],f=77,c=0;for(this.errormsg="",this.success=!0,this.M=0,this.u=s,this.o=0;this.o<this.u.length;)this.d()?(this.c>=60||this.c===51)&&f&64||this.c===3&&f&4?(this.l!=="+"&&(c++,this.b(o,u,1)),f=77):this.v()||((f&2)==0&&this.w(this.o,"unexpected operator"),c+=2,this.b(o,u,2),f=77):this.k()?((f&1)==0&&this.w(this.o,"unexpected number"),h=new t(0,0,0,this.f),o.push(h),f=50):this.m()?((f&1)==0&&this.w(this.o,"unexpected string"),h=new t(0,0,0,this.f),o.push(h),f=50):this.x()?((f&8)==0&&this.w(this.o,'unexpected "("'),f&128&&(c+=2,this.c=-2,this.l=-1,this.b(o,u,4)),f=333):this.g()?(f&256?(h=new t(0,0,0,[]),o.push(h)):(f&16)==0&&this.w(this.o,'unexpected ")"'),f=186):this.y()?((f&32)==0&&this.w(this.o,'unexpected ","'),this.b(o,u,2),c+=2,f=77):this.j()?((f&1)==0&&this.w(this.o,"unexpected constant"),e=new t(0,0,0,this.f),o.push(e),f=50):this.I(r=this.O())?((f&4)==0&&this.w(this.o,"unexpected function"),this.b(o,u,1),c++,f=77):this.q(r)?((f&1)==0&&this.w(this.o,"unexpected variable"),n=new t(3,this.l,0,0),o.push(n),f=186):this.C()||this.w(this.o,this.errormsg===""?"unknown character":this.errormsg);for(this.M<0?this.w(this.o,'unmatched "()"'):this.M>=100&&(this.M=0,f&256&&(h=new t(0,0,0,[]),o.push(h))),c===o.length+u.length&&u.length>0&&u[u.length-1].t===2&&(u.pop(),c-=2);u.length>0;)a=u.pop(),o.push(a);return c+1!==o.length&&this.w(this.o,"parity"),new i(o,this)},evaluate(t,i){return this.p(t).evaluate(i)},w(t,i){throw this.success=!1,this.errormsg="parse error [column "+t+"]: "+i,this.column=t,new Error(this.errormsg)},b(i,s,h){for(var r=new t(h,this.l,this.c+this.M,0),e=h===1?-1:0;s.length>0&&r.s-s[s.length-1].s<=e;)i.push(s.pop());s.push(r)},k(){for(var t,i,s=this.o,h=!1,r=10;s<this.u.length;s++)if((i=this.u.charCodeAt(s))>=48&&i<=57);else{if(i!==46){if(i===69||i===101){for(s+=(i=this.u.charCodeAt(s+1))===43||i===45?1:0,h=!0;(i=this.u.charCodeAt(++s))>=48&&i<=57;);break}if(i===88||i===120){if(s-this.o!=1||this.u.charCodeAt(s-1)!==48)break;for(r=16;(i=this.u.charCodeAt(++s))>=48&&i<=57||i>=97&&i<=102||i>=65&&i<=70;);break}break}if(h)return!1;h=!0}return!(s<=this.o||(t=this.u.substring(this.o,s),this.f=h?parseFloat(t):parseInt(t,r===10&&this.u.charCodeAt(this.o)===48?8:r),this.o=s,0))},N(t,i){var s,h,r,e=[],n=!0;for(s=0;s<t.length;s++)if(h=t.charAt(s),n)h=="\\"?n=!1:e.push(h);else{switch(h){case"'":e.push("'");break;case"\\":e.push("\\");break;case"/":e.push("/");break;case"b":e.push("\b");break;case"f":e.push("\f");break;case"n":e.push("\n");break;case"r":e.push("\r");break;case"t":e.push("\t");break;case"u":r=parseInt(t.substring(s+1,s+5),16),e.push(String.fromCharCode(r)),s+=4;break;default:throw this.w(i+s,"Illegal escape sequence: '\\"+h+"'")}n=!0}return e.join("")},m(){var t=!1,i="",s=this.o;if(this.o<this.u.length&&this.u.charAt(this.o)=="'")for(this.o++;this.o<this.u.length;){if(this.u.charAt(this.o)=="'"&&i.slice(-1)!="\\"){this.o++,this.f=this.N(i,s),t=!0;break}i+=this.u.charAt(this.o),this.o++}return t},j(){var t,i;for(t in this.consts)if(t===this.u.substr(this.o,i=t.length))return this.f=this.consts[t],this.o+=i,!0;return!1},d(){var t=this.u.charCodeAt(this.o);if(t===111){if(this.u.charCodeAt(this.o+1)!==114)return!1;this.o++,this.c=1,this.l="or"}else if(t===97){if(this.u.charCodeAt(this.o+1)!==110||this.u.charCodeAt(this.o+2)!==100)return!1;this.o+=2,this.c=2,this.l="and"}else if(t===110){if(this.u.charCodeAt(this.o+1)!==111||this.u.charCodeAt(this.o+2)!==116)return!1;this.o+=2,this.c=3,this.l="not"}else if(t===124)this.u.charCodeAt(this.o+1)===124?(this.o++,this.c=11,this.l="||"):(this.c=21,this.l="|");else if(t===94)this.c=22,this.l="^";else if(t===38)this.u.charCodeAt(this.o+1)===38?(this.o++,this.c=12,this.l="&&"):(this.c=23,this.l="&");else if(t===61){if(this.u.charCodeAt(this.o+1)!==61)return!1;this.o++,this.c=31,this.l="=="}else if(t===33){if(this.u.charCodeAt(this.o+1)!==61)return!1;this.o++,this.c=31,this.l="!="}else if(t===62)(t=this.u.charCodeAt(this.o+1))===61?(this.o++,this.c=32,this.l=">="):t!==62?(this.c=32,this.l=">"):this.u.charCodeAt(this.o+2)===62?(this.o+=2,this.c=41,this.l=">>>"):(this.o++,this.c=41,this.l=">>");else if(t===60)t=this.u.charCodeAt(this.o+1),this.o++,t===60?(this.c=41,this.l="<<"):t===61?(this.c=32,this.l="<="):t===62?(this.c=32,this.l="!="):(this.o--,this.c=32,this.l="<");else if(t===58||t===65306)this.c=50,this.l=":";else if(t===43)this.c=51,this.l="+";else if(t===45)this.c=51,this.l="-";else if(t===8729||t===8226)this.c=52,this.l="*";else if(t===42)this.u.charCodeAt(this.o+1)===42?(this.o++,this.c=53,this.l="**"):(this.c=52,this.l="*");else if(t===47)this.c=52,this.l="/";else if(t===92)this.c=52,this.l="\\";else if(t===37)this.c=52,this.l="%";else if(t===33)this.c=61,this.l="!";else{if(t!==126)return!1;this.c=61,this.l="~"}return this.o++,!0},x(){var t=this.u.charCodeAt(this.o);return(t===40||t===65288)&&(this.o++,this.M+=100,!0)},g(){var t=this.u.charCodeAt(this.o);return(t===41||t===65289)&&(this.o++,this.M-=100,!0)},y(){var t=this.u.charCodeAt(this.o);return(t===44||t===59)&&(this.o++,this.c=-1,this.l=t===44?",":";",!0)},C(){var t=this.u.charCodeAt(this.o);return(t===32||t===9||t===10||t===13)&&(this.o++,!0)},O(){for(var t,i=this.o,s=this.u;i<s.length&&(!((t=s.charCodeAt(i))<65||t>122||t>90&&t<97)||!(i===this.o||t!=95&&(t<48||t>57)));i++);return s.substring(this.o,i)},I(t){return t.length>0&&t in this.e&&(this.l=t,this.c=61,this.o+=t.length,!0)},q(t){return t.length>0&&(this.l=t,this.c=61,this.o+=t.length,!0)},v(){return this.u.charCodeAt(this.o-1)===47&&this.u.charCodeAt(this.o)===42&&(this.o=this.u.indexOf("*/",this.o)+2,this.o===1&&(this.o=this.u.length),!0)},clean(){this.u=""}},typeof define=="function"?(__filename="math_parser.js",define(["require","exports"],(t,i)=>{Object.defineProperty(i,"__esModule",{value:!0}),i.MathParser=new MathParser})):(typeof globalThis!="undefined"?globalThis:window).MathParser=new MathParser})();