1/** 2* @project Ratio.js 3* @purpose Provides a Ratio(Fraction) object for Javascript. Similar to Fraction.py for Python. 4* @author Larry Battle , <http://bateru.com/news/> 5* @license MIT and GPL 3.0 6 MIT License <http://www.opensource.org/licenses/mit-license> 7 GPL v3 <http://opensource.org/licenses/GPL-3.0> 8* @info Project page: <https://github.com/LarryBattle/Ratio.js/> 9* @version 0.2.2, 2012.07.13 10* @note Uses YUI-DOC to generate documentation. 11**/var Ratio=function(e,t,n){if(this instanceof Ratio){this.divSign="/",this.alwaysReduce=!!n,this.type="",this.denominator=isNaN(""+t)?1:Math.abs(t),this.numerator=isNaN(""+e)?0:Ratio.getNumeratorWithSign(e,t||1);if(this.denominator&&this.alwaysReduce){var r=Ratio.reduce(this);this.numerator=r[0],this.denominator=r[1]}return this}return new Ratio(e,t,n)};Ratio.VERSION="0.2.2",Ratio.isNumeric=function(e){return!isNaN(parseFloat(e))&&isFinite(e)},Ratio.getValueIfDefined=function(e,t){return typeof t!="undefined"&&t!==null?t:e},Ratio.gcd=function(e,t){var n;t=+t&&+e?+t:0,e=t?e:1;while(t)n=e%t,e=t,t=n;return Math.abs(e)},Ratio.getNumeratorWithSign=function(e,t){var n=+e||1,r=+t||1,i=""+n*r;return/\-/.test(i.charAt(0))?-Math.abs(+e):Math.abs(+e)},Ratio.parseDecimal=function(e){var t=[],n;return Ratio.isNumeric(e)?(e=+e,/\d+\.\d+$/.test(e)?(n=e.toString().split(/\./),t[1]=Math.pow(10,n[1].length),t[0]=Math.abs(n[0])*t[1]+ +n[1],t[0]=/\-/.test(n[0])?-t[0]:t[0]):t=[e,1],t):t},Ratio.parseENotation=function(e){var t=[],n,r;return Ratio.isNumeric(e)?(e=+e,/e/i.test(e)?(r=e.toString().split(/e/i),n=Ratio.parseDecimal(r[0]),Math.abs(e)<1?(t[0]=n[0],t[1]=+(n[1]+"e"+Math.abs(+r[1]))):(t[0]=+(n[0]+"e"+Math.abs(+r[1])),t[1]=n[1])):t=Ratio.parseDecimal(e),t):t},Ratio.parseNumber=function(e){return Ratio.isNumeric(e)?/e/i.test(e)?Ratio.parseENotation(e):Ratio.parseDecimal(e):[]},Ratio.parseToArray=function(e){var t=[],n,r=/\//;return typeof e=="undefined"||e===null?t:(e instanceof Ratio?(t[0]=Ratio.getNumeratorWithSign(e.numerator,e.denominator),t[1]=Math.abs(e.denominator)):r.test(e)?(n=e.split(r),t[0]=Ratio.getNumeratorWithSign(n[0],n[1]),t[1]=Math.abs(+n[1])):t=Ratio.parseNumber(e),t)},Ratio.parse=function(e,t){var n=Ratio.parseToArray(e),r;return n.length&&typeof t!="undefined"&&t!==null&&(r=Ratio.parseToArray(t),n[0]*=r[1],n[1]*=r[0]),new Ratio(n[0],n[1])},Ratio.reduce=function(e,t){e=Ratio.parse(e,t);var n=e.numerator,r=e.denominator,i=Ratio.getRepeatProps(n/r);i.length&&(n=+i.join("")- +(i[0]+""+i[1]),r=Math.pow(10,i[1].length)*(Math.pow(10,i[2].length)-1));var s=Ratio.gcd(n,r);return[n/s,r/s]},Ratio.getRepeatProps=function(e){e=""+(e||"");var t=/(?:[^\.]+\.\d*)(\d{2,})+(?:\1)$/,n=[],r=t.exec(e),i,s=/^(\d+)(?:\1)$/;return r||(e=e.replace(/\d$/,""),r=t.exec(e)),r&&1<r.length&&/\.\d{10}/.test(r[0])&&(r[1]=s.test(r[1])?s.exec(r[1])[1]:r[1],i=new RegExp("("+r[1]+")+$"),n=e.split(/\./).concat(r[1]),n[1]=n[1].replace(i,"")),n},Ratio.getPrimeFactors=function(e){e=Math.floor(e);var t,n=[],r,i=Math.sqrt,s=1<e&&isFinite(e);while(s){t=i(e),r=2;if(e%r){r=3;while(e%r&&(r+=2)<t);}r=t<r?e:r,n.push(r),s=r!=e,e/=r}return n},Ratio.getCleanENotation=function(e){e=(+e||0).toString();if(/\.\d+(0|9){8,}\d?e/.test(e)){var t=e.match(/(?:\d+\.)(\d+)(?:e.*)/)[1].replace(/(0|9)+\d$/,"").length+1;e=(+e).toPrecision(t).toString()}return e},Ratio.prototype.toArray=function(){return[this.numerator,this.denominator]},Ratio.prototype.valueOf=function(e){return!e&&this.type=="string"?this.toLocaleString():this.numerator/this.denominator},Ratio.prototype.toLocaleString=function(){var e=""+this.numerator,t=this.valueOf(!0);+this.numerator&&this.denominator!=1&&(e+=this.divSign+Math.abs(this.denominator));if(+this.denominator===0||this.numerator%this.denominator===0)e=t;return isNaN(t)||this.type=="decimal"?t.toString():e},Ratio.prototype.toString=function(){return""+this.numerator+this.divSign+this.denominator},Ratio.prototype.clone=function(e,t,n,r){var i=Ratio.getValueIfDefined;e=i(this.numerator,e),t=i(this.denominator,t),r=i(this.alwaysReduce,r);var s=new Ratio(e,t,r);return s.type=i(this.type,n),s},Ratio.prototype.reduce=function(){var e=Ratio.reduce(this.numerator,this.denominator);return this.clone(e[0],e[1])},Ratio.prototype.add=function(e,t){if(!(e instanceof Ratio)||typeof t!="undefined")e=Ratio.parse(e,t);var n,r,i;return this.denominator==e.denominator?(r=this.numerator+e.numerator,i=this.denominator):(n=Ratio.gcd(this.denominator,e.denominator),r=(this.numerator*e.denominator+this.denominator*e.numerator)/n,i=this.denominator*e.denominator/n),this.clone(r,i)},Ratio.prototype.divide=function(e,t){if(!(e instanceof Ratio)||typeof t!="undefined")e=Ratio.parse(e,t);return this.clone(this.numerator*e.denominator,this.denominator*e.numerator)},Ratio.prototype.equals=function(e){return this.numerator/this.denominator==e.valueOf()},Ratio.prototype.multiply=function(e,t){if(!(e instanceof Ratio)||typeof t!="undefined")e=Ratio.parse(e,t);return this.clone(this.numerator*e.numerator,this.denominator*e.denominator)},Ratio.prototype.subtract=function(e,t){if(!(e instanceof Ratio)||typeof t!="undefined")e=Ratio.parse(e,t);return e.numerator=-e.numerator,this.add(e)},Ratio.prototype.descale=function(e){return this.clone(this.numerator/e,this.denominator/e)},Ratio.prototype.pow=function(e){return this.clone(Math.pow(this.numerator,+e),Math.pow(this.denominator,+e))},Ratio.prototype.scale=function(e){return this.clone(this.numerator*+e,this.denominator*+e)},Ratio.prototype.cleanFormat=function(){var e=/^\d+\.\d+$/;if(e.test(this.numerator)||e.test(this.denominator))return Ratio.parse(this.numerator,this.denominator);var t=this.clone();return t.numerator=Ratio.getCleanENotation(t.numerator),t.denominator=Ratio.getCleanENotation(t.denominator),t},Ratio.prototype.abs=function(){return this.clone(Math.abs(this.numerator))},Ratio.prototype.mod=function(){return this.clone(this.numerator%this.denominator,1)},Ratio.prototype.negate=function(){return this.clone(-this.numerator)},Ratio.prototype.isProper=function(){return Math.abs(this.numerator)<this.denominator},Ratio.prototype.findX=function(e){var t=(""+e).split("/");if(t.length!==2)return null;var n=isNaN(t[0])?1:0,r=n?"multiply":"divide";return Ratio(t[n])[r](this)},typeof exports!="undefined"&&(typeof module!="undefined"&&module.exports&&(exports=module.exports),exports.Ratio=Ratio);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.