cnum
Version:
Represent rational numbers in comfortably numeric way.
3 lines (2 loc) • 20.7 kB
JavaScript
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t||self).cnum={})}(this,function(t){function n(){n=function(){return t};var t={},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}}}t.wrap=c;var f={};function l(){}function p(){}function d(){}var v={};u(v,o,function(){return this});var g=Object.getPrototypeOf,y=g&&g(g(L([])));y&&y!==e&&r.call(y,o)&&(v=y);var b=d.prototype=l.prototype=Object.create(v);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=d,u(b,"constructor",d),u(d,"constructor",p),p.displayName=u(d,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var n="function"==typeof t&&t.constructor;return!!n&&(n===p||"GeneratorFunction"===(n.displayName||n.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,s,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},m(w.prototype),u(w.prototype,a,function(){return this}),t.AsyncIterator=w,t.async=function(n,e,r,i,o){void 0===o&&(o=Promise);var a=new w(c(n,e,r,i),o);return t.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]"}),t.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}},t.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}},t}function e(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 r(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(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 o(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 i(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)?i(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}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 a="0.1.3",s=/*#__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}(),u={"+":"add","-":"sub","*":"mul","/":"div","**":"pow","^":"pow","=":"set","==":"equals","<":"isLessThan",">":"isGreaterThan"},c=/*#__PURE__*/function(){function t(t){this.s=void 0,this.s=t}return t.prototype.lex=/*#__PURE__*/n().mark(function t(){var e,r,i,o,a,c,h,f;return n().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=!1,r=!1,i=!1,o=!1,a="",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 s(4,a);case 12:r=!1,a="",t.next=21;break;case 16:if(!i){t.next=21;break}return t.next=19,new s(0,a);case 19:i=!1,a="";case 21:return e=!0,a+=f,t.abrupt("continue",63);case 26:if(!e){t.next=31;break}return t.next=29,new s(2,"");case 29:e=!1,a="";case 31:if(!/^\d$/.exec(f)){t.next=37;break}return i||(r=!0),a+=f,t.abrupt("continue",63);case 37:if(!r){t.next=42;break}return t.next=40,new s(4,a);case 40:r=!1,a="";case 42:if(!(/^[a-z]$/.exec(f)||i&&/^\d$/.exec(f))){t.next=48;break}return i=!0,a+=f,t.abrupt("continue",63);case 48:if(!i){t.next=53;break}return t.next=51,new s(0,a);case 51:i=!1,a="";case 53:if(!((a+=f)in u)){t.next=60;break}return t.next=57,new s(3,a);case 57:return o=!1,a="",t.abrupt("continue",63);case 60:if(!o){t.next=62;break}throw'Invalid operator "'+a+'"';case 62:o=!0;case 63:c++,t.next=6;break;case 66:if(!e){t.next=69;break}return t.next=69,new s(2,"");case 69:if(!r){t.next=72;break}return t.next=72,new s(4,a);case 72:if(!i){t.next=75;break}return t.next=75,new s(0,a);case 75:case"end":return t.stop()}},t,this)}),t}(),h=/*#__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=o(this.tokens);!(t=e()).done;){var r=t.value;if(0===r.type){var i;if(!(r.s in this.identifiers))throw'"'+r.s+'" is undefined';n+=BigInt(null!=(i=this.identifiers[r.s])?i:-1)}else 4===r.type&&(n+=BigInt(r.s))}return n},n.toString=function(){return this.evaluate().toString()},t}(),f=1e-16,l=/*#__PURE__*/n().mark(d),p=function(t){if(1n===t)return!1;for(var n=2n;n*n<=t;n++)if(t%n===0n)return!1;return!0};function d(){var t;return n().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:t=2n;case 1:if(!p(t)){n.next=5;break}return n.next=5,t;case 5:t++,n.next=1;break;case 8:case"end":return n.stop()}},l)}var v=function(t){for(var n,e=[],r=o(d());!(n=r()).done;){for(var i=n.value,a=0n;t%i===0n;)a++,t/=i;if(a&&e.push([i,a]),1n===t)break}return e},g=/*#__PURE__*/n().mark(b),y=/*#__PURE__*/n().mark(m);function b(t){var e,r,i,o,a,s,u;return n().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:e=1n,r=0n,i=0n,o=1n,a=new w(1n),s=0;case 3:if(!(s<512)){n.next=15;break}if(!a.approximates(t)){n.next=6;break}return n.abrupt("break",15);case 6:return u=t>+a,n.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++,n.next=3;break;case 15:case"end":return n.stop()}},g)}function m(t){var e,r,i,a,s;return n().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:e=!0,r=0,i=o(b(t));case 3:if((a=i()).done){n.next=15;break}if((s=a.value)!==e){n.next=9;break}r++,n.next=13;break;case 9:return n.next=11,r;case 11:r=1,e=s;case 13:n.next=3;break;case 15:return n.next=17,r+1;case 17:case"end":return n.stop()}},y)}var w=/*#__PURE__*/function(){function t(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 e=t.prototype;return e.valueOf=function(){return Number(this.n)/Number(this.d)},e.toString=function(){return this.n.toString()+(1n===this.d?"":"/"+this.d.toString())},e.clone=function(){return new t(this.n,this.d)},e.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)},e.add=function(n){var e=new t(this.n*n.d+n.n*this.d,this.d*n.d);return e.normalize(),e},e.sub=function(t){return this.add(t.neg())},e.mul=function(n){var e=new t(this.n*n.n,this.d*n.d);return e.normalize(),e},e.div=function(n){var e=new t(this.n*n.d,this.d*n.n);return e.normalize(),e},e.mediant=function(n){var e=new t(this.n+n.n,this.d+n.d);return e.normalize(),e},e.min=function(t){return this.isLessThan(t)?this:t},e.max=function(t){return this.isGreaterThan(t)?this:t},e.pow=function(n){if(0n===n.n)return new t(1n);if(1n===n.d)return new t(Math.pow(Number(this.n),Number(n.n)),Math.pow(Number(this.d),Number(n.n)));var e=Math.pow(+this,+n);return x(e)},e.dot=function(t){return this.n*t.n+this.d*t.d},e.equals=function(t){return this.n===t.n&&this.d===t.d},e.approximates=function(t){return Math.abs(+this-t)<f},e.isGreaterThan=function(t){return this.n*t.d>t.n*this.d},e.isLessThan=function(t){return this.n*t.d<t.n*this.d},e.abs=function(){var t=this.clone();return t.n<0&&(t.n=-t.n),t},e.neg=function(){var t=this.clone();return t.n=-t.n,t},e.isNegative=function(){return this.n<0},e.isFinite=function(){return 0n!==this.d},e.inv=function(){return new t(this.d,this.n)},e.sqrt=function(){return this.root(2)},e.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 x(Math.pow(+this,1/t))},e.round=function(){return BigInt(Math.round(+this))},e.floor=function(){return BigInt(Math.floor(+this))},e.ceil=function(){return BigInt(Math.ceil(+this))},e.psin=function(){if(0n===this.d)return new t(0n);var n=new t(1),e=new t(2),r=e.mul(this),i=n.add(this.pow(e));return r.div(i)},e.pcos=function(){if(0n===this.d)return new t(-1n);var n=new t(1),e=new t(2),r=this.pow(e),i=n.sub(r),o=n.add(r);return i.div(o)},e.ptan=function(){return this.psin().div(this.pcos())},e.mixedFractionString=function(){var n=this.isNegative()?this.ceil():this.floor(),e=this.sub(new t(n)).toString();return n?n+" + "+e:e},e.continuedFraction=/*#__PURE__*/n().mark(function t(){var e,r,i;return n().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=o(m(+this));case 6:if((r=e()).done){t.next=12;break}return i=r.value,t.next=10,i;case 10:t.next=6;break;case 12:case"end":return t.stop()}},t,this)}),e.continuedFractionString=function(){for(var t,n=[],e=o(this.continuedFraction());!(t=e()).done;)n.push(t.value.toString());var r=n.shift();if(void 0!==r&&0n!==this.d){var i=r.toString();return n.length&&(i+="; "+n.join(", ")),"["+i+"]"}return"[]"},e.primeFactorization=function(){var t=[];return 1n!==this.n&&t.push.apply(t,v(this.n)),1n!==this.d&&t.push.apply(t,v(this.d).map(function(t){return t[1]=-t[1],t})),t.sort(function(t,n){return Number(t[0]-n[0])})},e.primeFactorizationString=function(){for(var t,n=[],e=o(this.primeFactorization());!(t=e()).done;){var r=t.value;n.push(1n===r[1]?r[0].toString():r[0]+"^"+r[1])}return n.join(" * ")},e.egyptianFraction=function(){var n=[],e=new t(1n),r=this.clone(),i=this.floor();if(i){var o=new t(i);n.push(o),r=r.sub(o)}if(0n===r.n)return n;for(;1n!==r.n;)e.d++,r.isGreaterThan(e)&&(n.push(e.clone()),r=r.sub(e));return n.push(r),n},e.egyptianFractionString=function(){return this.egyptianFraction().join(" + ")},e.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},e.babylonianFractionString=function(){for(var t,n=[],e=o(this.babylonianFraction());!(t=e()).done;)n.push(""+t.value);return n.join(" + ")},r(t,[{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")}}]),t}(),x=function(t){if(isNaN(t))return new w(0,0);if(Infinity===t)return new w(1,0);if(-Infinity===t)return new w(-1,0);if(Math.abs(t%1)<f)return new w(Math.round(t));if(Math.abs(1/t%1)<f)return new w(1,Math.round(1/t));var n=t<1,e=function(t){for(var n=1n,e=0n,r=0n,i=1n,o=new w(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},k=/*#__PURE__*/function(){function t(t){this.symbols=[],t&&(this.symbols=t.split(""))}return t.prototype.generator=/*#__PURE__*/n().mark(function t(){var e,r;return n().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()}},t,this)}),t}(),S=/*#__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 k("xyzw").generator(),r=0;r<this.dimension;r++)this.latinSymbols+=e.next().value;for(var i=(new k).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 w,e=0,r=Object.entries(this.coefficents);e<r.length;e++){for(var i=r[e],o=i[0],a=new w(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 w(1),l=parseInt(null!=(h=s[u])?h:"1",10);a=a.mul(f.pow(new w(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,d=parseInt(null!=(l=c[h])?l:"0",10);if(d>0)a.push((null!=(p=this.greekSymbols[h])?p:"?")+"<sup>"+d+"</sup>");else if(-1===d){var v;s.push(null!=(v=this.greekSymbols[h])?v:"?")}else{var g;s.push((null!=(g=this.greekSymbols[h])?g:"?")+"<sup>"+-d+"</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}(),j=/*#__PURE__*/function(){function t(){}return t.evaluate=function(t){var n=new c(t);return new h(n.lex()).toString()},r(t,null,[{key:"version",get:function(){return a}}]),t}();t.Polyrat=S,t.Rat=w,t.cnum=j,t.floatToRat=x,t.parseRat=function(t){if("NaN"===t)return new w(0,0);if("Infinity"===t)return new w(1,0);if("-Infinity"===t)return new w(-1,0);var n=t.split("/",2),e=n[0],r=n[1];return void 0===r?x(Number(e)):new w(BigInt(null!=e?e:1),BigInt(r))},t.stringToPolyrat=function(t){return new S(JSON.parse(t))},t.version=a});
//# sourceMappingURL=index.umd.js.map