/* Fraction.js v4.0.0 09/09/2015 http://www.xarg.org/2014/03/rational-numbers-in-javascript/ Copyright (c) 2015, Robert Eisele (robert@xarg.org) Dual licensed under the MIT or GPL Version 2 licenses. */ (function(w){function q(a,c){if(!a)return c;if(!c)return a;for(;;){a%=c;if(!a)return c;c%=a;if(!c)return a}}function x(a){for(;0===a%2;a/=2);for(;0===a%5;a/=5);if(1===a)return 0;for(var c=10%a,d=1;1!==c;d++)if(c=10*c%a,2E3a&&(e=a,a=-a);if(0===a%1)d=a;else if(0=g&&1E7>=t;)if(d=(f+q)/(g+t),a===d){1E7>=g+t?(d=f+q,l=g+t):t>g?(d=q,l=t):(d=f,l=g);break}else a>d?(f+=q,g+=t):(q+=f,t+=g),1E7e?-1:1;b.n=Math.abs(d);b.d=Math.abs(l)}function v(a){function c(){} function d(){var c=Error.apply(this,arguments);c.name=this.name=a;this.stack=c.stack;this.message=c.message}c.prototype=Error.prototype;d.prototype=new c;return d}function p(a,c){if(isNaN(a=parseInt(a,10)))throw new u;return a*c}function e(a,c){if(!(this instanceof e))return new e(a,c);k(a,c);a=e.REDUCE?q(b.d,b.n):1;this.s=b.s;this.n=b.n/a;this.d=b.d/a}var b={s:1,n:0,d:1},y=e.DivisionByZero=v("DivisionByZero"),u=e.InvalidParameter=v("InvalidParameter");e.REDUCE=1;e.prototype={s:1,n:0,d:1,abs:function(){return new e(this.n, this.d)},neg:function(){return new e(-this.s*this.n,this.d)},add:function(a,c){k(a,c);return new e(this.s*this.n*b.d+b.s*this.d*b.n,this.d*b.d)},sub:function(a,c){k(a,c);return new e(this.s*this.n*b.d-b.s*this.d*b.n,this.d*b.d)},mul:function(a,c){k(a,c);return new e(this.s*b.s*this.n*b.n,this.d*b.d)},div:function(a,c){k(a,c);return new e(this.s*b.s*this.n*b.d,this.d*b.n)},clone:function(){return new e(this)},mod:function(a,c){if(isNaN(this.n)||isNaN(this.d))return new e(NaN);if(void 0===a)return new e(this.s* this.n%this.d,1);k(a,c);0===b.n&&0===this.d&&e(0,0);return new e(this.s*b.d*this.n%(b.n*this.d),b.d*this.d)},gcd:function(a,c){k(a,c);return new e(q(b.n,this.n),b.d*this.d/q(b.d,this.d))},lcm:function(a,c){k(a,c);return 0===b.n&&0===this.n?new e:new e(b.n*this.n/q(b.n,this.n),q(b.d,this.d))},ceil:function(a){a=Math.pow(10,a||0);return isNaN(this.n)||isNaN(this.d)?new e(NaN):new e(Math.ceil(a*this.s*this.n/this.d),a)},floor:function(a){a=Math.pow(10,a||0);return isNaN(this.n)||isNaN(this.d)?new e(NaN): new e(Math.floor(a*this.s*this.n/this.d),a)},round:function(a){a=Math.pow(10,a||0);return isNaN(this.n)||isNaN(this.d)?new e(NaN):new e(Math.round(a*this.s*this.n/this.d),a)},inverse:function(){return new e(this.s*this.d,this.n)},pow:function(a){return 0>a?new e(Math.pow(this.s*this.d,-a),Math.pow(this.n,-a)):new e(Math.pow(this.s*this.n,a),Math.pow(this.d,a))},equals:function(a,c){k(a,c);return this.s*this.n*b.d===b.s*b.n*this.d},compare:function(a,c){k(a,c);var d=this.s*this.n*b.d-b.s*b.n*this.d; return(0d)},divisible:function(a,c){k(a,c);return!(!(b.n*this.d)||this.n*b.d%(b.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(a){var c,d="",e=this.n,b=this.d;0>this.s&&(d+="-");1===b?d+=e:(a&&0<(c=Math.floor(e/b))&&(d=d+c+" ",e%=b),d=d+e+"/",d+=b);return d},toLatex:function(a){var c,d="",e=this.n,b=this.d;0>this.s&&(d+="-");1===b?d+=e:(a&&0<(c=Math.floor(e/b))&&(d+=c,e%=b),d=d+"\\frac{"+e+"}{"+b,d+="}");return d},toContinued:function(){var a,c=this.n,d=this.d, e=[];do e.push(Math.floor(c/d)),a=c%d,c=d,d=a;while(1!==c);return e},toString:function(){var a,c=this.n,d=this.d;if(isNaN(c)||isNaN(d))return"NaN";e.REDUCE||(a=q(c,d),c/=a,d/=a);a=String(c).split("");var c=0,b=[~this.s?"":"-","",""],k="",p=x(d),m;a:{m=1;var n;n=p;for(var h=10,r=1;0>=1)n&1&&(r=r*h%d);n=r;for(h=0;300>h;h++){if(m===n){m=h;break a}m=10*m%d;n=10*n%d}m=0}n=-1;for(var h=1,r=15+p+m+a.length,f=0;f=d?(b[h]+=k+(c/d|0),k="",c%=d):1