UNPKG

cnum

Version:

Represent rational numbers in comfortably numeric way.

3 lines (2 loc) 20.6 kB
function t(){t=function(){return n};var n={},e=Object.prototype,r=e.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function u(t,n,e){return Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[n]}try{u({},"")}catch(t){u=function(t,n,e){return t[n]=e}}function c(t,n,e,r){var i=Object.create((n&&n.prototype instanceof l?n:l).prototype),o=new j(r||[]);return i._invoke=function(t,n,e){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return{value:void 0,done:!0}}for(e.method=i,e.arg=o;;){var a=e.delegate;if(a){var s=x(a,e);if(s){if(s===f)continue;return s}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===r)throw r="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);r="executing";var u=h(t,n,e);if("normal"===u.type){if(r=e.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(r="completed",e.method="throw",e.arg=u.arg)}}}(t,e,o),i}function h(t,n,e){try{return{type:"normal",arg:t.call(n,e)}}catch(t){return{type:"throw",arg:t}}}n.wrap=c;var f={};function l(){}function p(){}function v(){}var d={};u(d,o,function(){return this});var g=Object.getPrototypeOf,y=g&&g(g(L([])));y&&y!==e&&r.call(y,o)&&(d=y);var b=v.prototype=l.prototype=Object.create(d);function m(t){["next","throw","return"].forEach(function(n){u(t,n,function(t){return this._invoke(n,t)})})}function w(t,n){function e(i,o,a,s){var u=h(t[i],t,o);if("throw"!==u.type){var c=u.arg,f=c.value;return f&&"object"==typeof f&&r.call(f,"__await")?n.resolve(f.__await).then(function(t){e("next",t,a,s)},function(t){e("throw",t,a,s)}):n.resolve(f).then(function(t){c.value=t,a(c)},function(t){return e("throw",t,a,s)})}s(u.arg)}var i;this._invoke=function(t,r){function o(){return new n(function(n,i){e(t,r,n,i)})}return i=i?i.then(o,o):o()}}function x(t,n){var e=t.iterator[n.method];if(void 0===e){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=void 0,x(t,n),"throw"===n.method))return f;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var r=h(e,t.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,f;var i=r.arg;return i?i.done?(n[t.resultName]=i.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=void 0),n.delegate=null,f):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,f)}function k(t){var n={tryLoc:t[0]};1 in t&&(n.catchLoc=t[1]),2 in t&&(n.finallyLoc=t[2],n.afterLoc=t[3]),this.tryEntries.push(n)}function S(t){var n=t.completion||{};n.type="normal",delete n.arg,t.completion=n}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function L(t){if(t){var n=t[o];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,i=function n(){for(;++e<t.length;)if(r.call(t,e))return n.value=t[e],n.done=!1,n;return n.value=void 0,n.done=!0,n};return i.next=i}}return{next:F}}function F(){return{value:void 0,done:!0}}return p.prototype=v,u(b,"constructor",v),u(v,"constructor",p),p.displayName=u(v,s,"GeneratorFunction"),n.isGeneratorFunction=function(t){var n="function"==typeof t&&t.constructor;return!!n&&(n===p||"GeneratorFunction"===(n.displayName||n.name))},n.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,u(t,s,"GeneratorFunction")),t.prototype=Object.create(b),t},n.awrap=function(t){return{__await:t}},m(w.prototype),u(w.prototype,a,function(){return this}),n.AsyncIterator=w,n.async=function(t,e,r,i,o){void 0===o&&(o=Promise);var a=new w(c(t,e,r,i),o);return n.isGeneratorFunction(e)?a:a.next().then(function(t){return t.done?t.value:a.next()})},m(b),u(b,s,"Generator"),u(b,o,function(){return this}),u(b,"toString",function(){return"[object Generator]"}),n.keys=function(t){var n=[];for(var e in t)n.push(e);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},n.values=L,j.prototype={constructor:j,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(S),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function e(e,r){return a.type="throw",a.arg=t,n.next=e,r&&(n.method="next",n.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return e("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return e(o.catchLoc,!0);if(this.prev<o.finallyLoc)return e(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return e(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return e(o.finallyLoc)}}}},abrupt:function(t,n){for(var e=this.tryEntries.length-1;e>=0;--e){var i=this.tryEntries[e];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=n&&n<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=n,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(a)},complete:function(t,n){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&n&&(this.next=n),f},finish:function(t){for(var n=this.tryEntries.length-1;n>=0;--n){var e=this.tryEntries[n];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),S(e),f}},catch:function(t){for(var n=this.tryEntries.length-1;n>=0;--n){var e=this.tryEntries[n];if(e.tryLoc===t){var r=e.completion;if("throw"===r.type){var i=r.arg;S(e)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,e){return this.delegate={iterator:L(t),resultName:n,nextLoc:e},"next"===this.method&&(this.arg=void 0),f}},n}function n(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function e(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}function i(t,n){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return r(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?r(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o=/*#__PURE__*/function(){function t(t,n){this.type=void 0,this.s=void 0,this.type=t,this.s=n}return t.prototype.toString=function(){return this.type+"("+this.s+")"},t}(),a={"+":"add","-":"sub","*":"mul","/":"div","**":"pow","^":"pow","=":"set","==":"equals","<":"isLessThan",">":"isGreaterThan"},s=/*#__PURE__*/function(){function n(t){this.s=void 0,this.s=t}return n.prototype.lex=/*#__PURE__*/t().mark(function n(){var e,r,i,s,u,c,h,f;return t().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=!1,r=!1,i=!1,s=!1,u="",c=0;case 6:if(!(c<this.s.length)){t.next=66;break}if(f=null!=(h=this.s[c])?h:"?",!/^\s$/.exec(f)){t.next=26;break}if(!r){t.next=16;break}return t.next=12,new o(4,u);case 12:r=!1,u="",t.next=21;break;case 16:if(!i){t.next=21;break}return t.next=19,new o(0,u);case 19:i=!1,u="";case 21:return e=!0,u+=f,t.abrupt("continue",63);case 26:if(!e){t.next=31;break}return t.next=29,new o(2,"");case 29:e=!1,u="";case 31:if(!/^\d$/.exec(f)){t.next=37;break}return i||(r=!0),u+=f,t.abrupt("continue",63);case 37:if(!r){t.next=42;break}return t.next=40,new o(4,u);case 40:r=!1,u="";case 42:if(!(/^[a-z]$/.exec(f)||i&&/^\d$/.exec(f))){t.next=48;break}return i=!0,u+=f,t.abrupt("continue",63);case 48:if(!i){t.next=53;break}return t.next=51,new o(0,u);case 51:i=!1,u="";case 53:if(!((u+=f)in a)){t.next=60;break}return t.next=57,new o(3,u);case 57:return s=!1,u="",t.abrupt("continue",63);case 60:if(!s){t.next=62;break}throw'Invalid operator "'+u+'"';case 62:s=!0;case 63:c++,t.next=6;break;case 66:if(!e){t.next=69;break}return t.next=69,new o(2,"");case 69:if(!r){t.next=72;break}return t.next=72,new o(4,u);case 72:if(!i){t.next=75;break}return t.next=75,new o(0,u);case 75:case"end":return t.stop()}},n,this)}),n}(),u=/*#__PURE__*/function(){function t(t){this.tokens=void 0,this.identifiers={},this.tokens=t}var n=t.prototype;return n.evaluate=function(){for(var t,n=0n,e=i(this.tokens);!(t=e()).done;){var r=t.value;if(0===r.type){var o;if(!(r.s in this.identifiers))throw'"'+r.s+'" is undefined';n+=BigInt(null!=(o=this.identifiers[r.s])?o:-1)}else 4===r.type&&(n+=BigInt(r.s))}return n},n.toString=function(){return this.evaluate().toString()},t}(),c=/*#__PURE__*/t().mark(f),h=function(t){if(1n===t)return!1;for(var n=2n;n*n<=t;n++)if(t%n===0n)return!1;return!0};function f(){var n;return t().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:n=2n;case 1:if(!h(n)){t.next=5;break}return t.next=5,n;case 5:n++,t.next=1;break;case 8:case"end":return t.stop()}},c)}var l=function(t){for(var n,e=[],r=i(f());!(n=r()).done;){for(var o=n.value,a=0n;t%o===0n;)a++,t/=o;if(a&&e.push([o,a]),1n===t)break}return e},p=/*#__PURE__*/t().mark(d),v=/*#__PURE__*/t().mark(g);function d(n){var e,r,i,o,a,s,u;return t().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=1n,r=0n,i=0n,o=1n,a=new y(1n),s=0;case 3:if(!(s<512)){t.next=15;break}if(!a.approximates(n)){t.next=6;break}return t.abrupt("break",15);case 6:return u=n>+a,t.next=9,u;case 9:u?(r+=e,o+=i):(e+=r,i+=o),a.n=e+r,a.d=i+o;case 12:s++,t.next=3;break;case 15:case"end":return t.stop()}},p)}function g(n){var e,r,o,a,s;return t().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=!0,r=0,o=i(d(n));case 3:if((a=o()).done){t.next=15;break}if((s=a.value)!==e){t.next=9;break}r++,t.next=13;break;case 9:return t.next=11,r;case 11:r=1,e=s;case 13:t.next=3;break;case 15:return t.next=17,r+1;case 17:case"end":return t.stop()}},v)}var y=/*#__PURE__*/function(){function n(t,n){void 0===t&&(t=0n),void 0===n&&(n=1n),this.n=void 0,this.d=void 0,this.n=BigInt(t),this.d=BigInt(n),this.normalize()}var r=n.prototype;return r.valueOf=function(){return Number(this.n)/Number(this.d)},r.toString=function(){return this.n.toString()+(1n===this.d?"":"/"+this.d.toString())},r.clone=function(){return new n(this.n,this.d)},r.normalize=function(){if(0n!==this.n)if(0n!==this.d)if(this.n!==this.d){this.d<0n&&(this.n=-this.n,this.d=-this.d);var t=function(t,n){if(1n===n||1n===t)return 1n;for(;0n!==n;){var e=t%n;t=n,n=e}return t<0n?-t:t}(this.n,this.d);this.n/=t,this.d/=t}else this.n=this.d=1n;else this.n=this.n>0n?1n:-1n;else 0n!==this.d&&(this.d=1n)},r.add=function(t){var e=new n(this.n*t.d+t.n*this.d,this.d*t.d);return e.normalize(),e},r.sub=function(t){return this.add(t.neg())},r.mul=function(t){var e=new n(this.n*t.n,this.d*t.d);return e.normalize(),e},r.div=function(t){var e=new n(this.n*t.d,this.d*t.n);return e.normalize(),e},r.mediant=function(t){var e=new n(this.n+t.n,this.d+t.d);return e.normalize(),e},r.min=function(t){return this.isLessThan(t)?this:t},r.max=function(t){return this.isGreaterThan(t)?this:t},r.pow=function(t){if(0n===t.n)return new n(1n);if(1n===t.d)return new n(Math.pow(Number(this.n),Number(t.n)),Math.pow(Number(this.d),Number(t.n)));var e=Math.pow(+this,+t);return b(e)},r.dot=function(t){return this.n*t.n+this.d*t.d},r.equals=function(t){return this.n===t.n&&this.d===t.d},r.approximates=function(t){return Math.abs(+this-t)<1e-16},r.isGreaterThan=function(t){return this.n*t.d>t.n*this.d},r.isLessThan=function(t){return this.n*t.d<t.n*this.d},r.abs=function(){var t=this.clone();return t.n<0&&(t.n=-t.n),t},r.neg=function(){var t=this.clone();return t.n=-t.n,t},r.isNegative=function(){return this.n<0},r.isFinite=function(){return 0n!==this.d},r.inv=function(){return new n(this.d,this.n)},r.sqrt=function(){return this.root(2)},r.root=function(t){if(0n===this.n||0n===this.d||this.n===this.d)return this.clone();if(this.isNegative())throw"Roots of negative numbers like "+this.toString()+" are too complex for this basic library";return b(Math.pow(+this,1/t))},r.round=function(){return BigInt(Math.round(+this))},r.floor=function(){return BigInt(Math.floor(+this))},r.ceil=function(){return BigInt(Math.ceil(+this))},r.psin=function(){if(0n===this.d)return new n(0n);var t=new n(1),e=new n(2),r=e.mul(this),i=t.add(this.pow(e));return r.div(i)},r.pcos=function(){if(0n===this.d)return new n(-1n);var t=new n(1),e=new n(2),r=this.pow(e),i=t.sub(r),o=t.add(r);return i.div(o)},r.ptan=function(){return this.psin().div(this.pcos())},r.mixedFractionString=function(){var t=this.isNegative()?this.ceil():this.floor(),e=this.sub(new n(t)).toString();return t?t+" + "+e:e},r.continuedFraction=/*#__PURE__*/t().mark(function n(){var e,r,o;return t().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(0n!==this.n&&0n!==this.d){t.next=5;break}return t.next=3,+this;case 3:t.next=12;break;case 5:e=i(g(+this));case 6:if((r=e()).done){t.next=12;break}return o=r.value,t.next=10,o;case 10:t.next=6;break;case 12:case"end":return t.stop()}},n,this)}),r.continuedFractionString=function(){for(var t,n=[],e=i(this.continuedFraction());!(t=e()).done;)n.push(t.value.toString());var r=n.shift();if(void 0!==r&&0n!==this.d){var o=r.toString();return n.length&&(o+="; "+n.join(", ")),"["+o+"]"}return"[]"},r.primeFactorization=function(){var t=[];return 1n!==this.n&&t.push.apply(t,l(this.n)),1n!==this.d&&t.push.apply(t,l(this.d).map(function(t){return t[1]=-t[1],t})),t.sort(function(t,n){return Number(t[0]-n[0])})},r.primeFactorizationString=function(){for(var t,n=[],e=i(this.primeFactorization());!(t=e()).done;){var r=t.value;n.push(1n===r[1]?r[0].toString():r[0]+"^"+r[1])}return n.join(" * ")},r.egyptianFraction=function(){var t=[],e=new n(1n),r=this.clone(),i=this.floor();if(i){var o=new n(i);t.push(o),r=r.sub(o)}if(0n===r.n)return t;for(;1n!==r.n;)e.d++,r.isGreaterThan(e)&&(t.push(e.clone()),r=r.sub(e));return t.push(r),t},r.egyptianFractionString=function(){return this.egyptianFraction().join(" + ")},r.babylonianFraction=function(){for(var t=[],n=Number(this.floor()),e=Math.abs(+this-n),r=0,i=0;n>0;i++)0!=(r=n%60)&&t.unshift(r+" * 60^"+i),n=(n-r)/60;for(var o=-1;e>1e-10;o--)e*=60,e-=r=Math.floor(e),0!==r&&t.push(r+" * 60^"+o),n=(n-r)/60;return t},r.babylonianFractionString=function(){for(var t,n=[],e=i(this.babylonianFraction());!(t=e()).done;)n.push(""+t.value);return n.join(" + ")},e(n,[{key:"profile",get:function(){var t=["Rat: "+this.toString()+" (≈"+ +this+")"];return t.push("Mixed: "+this.mixedFractionString()),t.push("Continued: "+this.continuedFractionString()),t.push("Factorization: "+this.primeFactorizationString()),t.push("Egyptian: "+this.egyptianFractionString()),t.push("Babylonian: "+this.babylonianFractionString()),t.push("psin(t): "+this.psin().toString()),t.push("pcos(t): "+this.pcos().toString()),t.push("ptan(t): "+this.ptan().toString()),t.join("\n")}}]),n}(),b=function(t){if(isNaN(t))return new y(0,0);if(Infinity===t)return new y(1,0);if(-Infinity===t)return new y(-1,0);if(Math.abs(t%1)<1e-16)return new y(Math.round(t));if(Math.abs(1/t%1)<1e-16)return new y(1,Math.round(1/t));var n=t<1,e=function(t){for(var n=1n,e=0n,r=0n,i=1n,o=new y(1n),a=0;a<512&&!o.approximates(t);a++)+o>t?(n+=e,r+=i):(e+=n,i+=r),o.n=n+e,o.d=r+i;return o}(Math.abs(t));return n?e.neg():e},m=/*#__PURE__*/function(){function n(t){this.symbols=[],t&&(this.symbols=t.split(""))}return n.prototype.generator=/*#__PURE__*/t().mark(function n(){var e,r;return t().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=0;case 1:if(!(e<this.symbols.length)){t.next=6;break}return t.next=4,null!=(r=this.symbols[e])?r:"?";case 4:t.next=8;break;case 6:return t.next=8,String.fromCharCode(945+e-this.symbols.length);case 8:e++,t.next=1;break;case 11:case"end":return t.stop()}},n,this)}),n}(),w=/*#__PURE__*/function(){function t(t){if(this.coefficents={},this.dimension=0,this.latinSymbols="",this.greekSymbols="",t&&(this.coefficents=t),Object.keys(this.coefficents).length){var n=Object.keys(this.coefficents);this.dimension=n[0]?n[0].split(",").length:0}for(var e=new m("xyzw").generator(),r=0;r<this.dimension;r++)this.latinSymbols+=e.next().value;for(var i=(new m).generator(),o=0;o<this.dimension;o++)this.greekSymbols+=i.next().value}var n=t.prototype;return n.evaluate=function(t){for(var n=new y,e=0,r=Object.entries(this.coefficents);e<r.length;e++){for(var i=r[e],o=i[0],a=new y(i[1]),s=o.split(","),u=0;u<s.length;u++)if(u in t){var c,h,f=null!=(c=t[u])?c:new y(1),l=parseInt(null!=(h=s[u])?h:"1",10);a=a.mul(f.pow(new y(l)))}n=n.add(a)}return n},n.toString=function(){return this.constructor.name+"("+this.toJSON()+")"},n.toJSON=function(){for(var t=[],n=0,e=Object.entries(this.coefficents);n<e.length;n++){var r=e[n];t.push('"'+r[0]+'":"'+r[1].toString()+'"')}return"{"+t.join(",")+"}"},n.toHTMLFormula=function(){for(var t=[],n=0,e=Object.entries(this.coefficents);n<e.length;n++){var r=e[n],i=r[0],o=[],a=r[1].toString();"1"!==a&&o.push(a);for(var s=i.split(","),u=0;u<s.length;u++){var c,h,f;"0"!==s[u]&&o.push("1"===s[u]?null!=(c=this.latinSymbols[u])?c:"?":(null!=(h=this.latinSymbols[u])?h:"?")+"<sup>"+parseInt(null!=(f=s[u])?f:"?",10)+"</sup>")}o&&t.push(o.join(""))}return 0===t.length?"0":t.join(" + ")},n.toStandardAlphaFormHTML=function(){var t=[],n=[];if(!Object.keys(this.coefficents).length)return"0";for(var e=0,r=Object.entries(this.coefficents);e<r.length;e++){var i=r[e],o=i[0],a=[],s=[],u=i[1].toString();"1"!==u&&a.push(u);for(var c=o.split(","),h=0;h<c.length;h++)if("0"!==c[h])if("1"===c[h]){var f;a.push(null!=(f=this.greekSymbols[h])?f:"?")}else{var l,p,v=parseInt(null!=(l=c[h])?l:"0",10);if(v>0)a.push((null!=(p=this.greekSymbols[h])?p:"?")+"<sup>"+v+"</sup>");else if(-1===v){var d;s.push(null!=(d=this.greekSymbols[h])?d:"?")}else{var g;s.push((null!=(g=this.greekSymbols[h])?g:"?")+"<sup>"+-v+"</sup>")}}a.length&&t.push(a.join("")),s.length&&n.push(s.join(""))}return 0===t.length&&t.push("1"),0===n.length?t.join(" + "):t.join(" + ")+" / "+n.join(" + ")},n.toCalcFormula=function(){for(var t=[],n=0,e=Object.entries(this.coefficents);n<e.length;n++){var r=e[n],i=r[0],o=[],a=r[1].toString();"1"!==a&&o.push(a);for(var s=i.split(","),u=0;u<s.length;u++){var c,h,f;"0"!==s[u]&&o.push("1"===s[u]?null!=(c=this.latinSymbols[u])?c:"?":(null!=(h=this.latinSymbols[u])?h:"?")+"^"+parseInt(null!=(f=s[u])?f:"0",10))}o.length&&t.push(o.join("*"))}return 0===t.length?"0":t.join(" + ")},n.toGLSLFormula=function(){for(var t=[],n=0,e=Object.entries(this.coefficents);n<e.length;n++){var r=e[n],i=r[0],o=[],a=r[1].toString();"1"!==a&&o.push(a+".0");for(var s=i.split(","),u=0;u<s.length;u++)if("0"!==s[u]){var c,h,f=parseInt(null!=(c=s[u])?c:"0",10),l=f<0;l&&(o.push("1.0/(1.0"),f=-f),o.push((null!=(h=this.latinSymbols[u])?h:"?").repeat(f).split("").join("*")),l&&o.push("1.0)")}o.length&&t.push(o.join("*"))}return 0===t.length?"0.0":t.join("+")},n.clone=function(){return new t(this.coefficents)},t}(),x=/*#__PURE__*/function(){function t(){}return t.evaluate=function(t){var n=new s(t);return new u(n.lex()).toString()},e(t,null,[{key:"version",get:function(){return"0.1.3"}}]),t}();exports.Polyrat=w,exports.Rat=y,exports.cnum=x,exports.floatToRat=b,exports.parseRat=function(t){if("NaN"===t)return new y(0,0);if("Infinity"===t)return new y(1,0);if("-Infinity"===t)return new y(-1,0);var n=t.split("/",2),e=n[0],r=n[1];return void 0===r?b(Number(e)):new y(BigInt(null!=e?e:1),BigInt(r))},exports.stringToPolyrat=function(t){return new w(JSON.parse(t))},exports.version="0.1.3"; //# sourceMappingURL=index.cjs.map