Socket
Socket
Sign inDemoInstall

fraction.js

Package Overview
Dependencies
0
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.8.0 to 2.9.0

2

bower.json
{
"name": "fraction.js",
"main": "fraction.js",
"version": "2.8.0",
"version": "2.9.0",
"homepage": "http://www.xarg.org/2014/03/precise-calculations-in-javascript/",

@@ -6,0 +6,0 @@ "description": "A rational number library",

/**
* @license Fraction.js v2.8.0 01/06/2015
* @license Fraction.js v2.9.0 01/06/2015
* http://www.xarg.org/2014/03/precise-calculations-in-javascript/

@@ -583,3 +583,3 @@ *

**/
'toFraction': function() {
'toFraction': function(excludeWhole) {

@@ -596,4 +596,4 @@ var whole, str = "";

} else {
whole = Math.floor(n / d);
if (whole > 0) {
if (excludeWhole && (whole = Math.floor(n / d)) > 0) {
str+= whole;

@@ -616,3 +616,3 @@ str+= " ";

**/
'toLatex': function() {
'toLatex': function(excludeWhole) {

@@ -629,2 +629,8 @@ var whole, str = "";

} else {
if (excludeWhole && (whole = Math.floor(n / d)) > 0) {
str+= whole;
n %= d;
}
str+= "\\frac{";

@@ -631,0 +637,0 @@ str+= n;

/*
Fraction.js v2.8.0 01/06/2015
Fraction.js v2.9.0 01/06/2015
http://www.xarg.org/2014/03/precise-calculations-in-javascript/

@@ -8,9 +8,10 @@

*/
(function(w){"use strict";function u(a,b){if(!a)return b;if(!b)return a;for(;;){a%=b;if(!a)return b;b%=a;if(!b)return a}}function x(a){for(;0===a%2;a/=2);for(;0===a%5;a/=5);if(1===a)return 0;for(var b=10%a,e=1;1!==b;e++)if(b=10*b%a,2E3<e)return 0;return e}function k(a,b){var e=0,p=1,g=1,k=0,m=0,l=0,h=1,q=1,d=0,f=1,t=1,r=1;if(void 0!==a&&null!==a)if(void 0!==b)e=a,p=b,g=e*p;else switch(typeof a){case "object":"d"in a&&"n"in a?(e=a.n,p=a.d,"s"in a&&(e*=a.s)):0 in a?(e=a[0],1 in a&&(p=a[1])):v();g=e*p;break;case "number":0>
a&&(g=a,a=-a);if(0===a%1)e=a;else if(0<a){1<=a&&(q=Math.pow(10,Math.floor(1+Math.log(a)/Math.LN10)),a/=q);for(;1E7>=f&&1E7>=r;)if(e=(d+t)/(f+r),a===e){1E7>=f+r?(e=d+t,p=f+r):r>f?(e=t,p=r):(e=d,p=f);break}else a>e?(d+=t,f+=r):(t+=d,r+=f),1E7<f?(e=t,p=r):(e=d,p=f);e*=q}break;case "string":f=a.match(/\d+|./g);"-"===f[d]?(g=-1,d++):"+"===f[d]&&d++;if(f.length===d+1)m=n(f[d++],g);else if("."===f[d+1]||"."===f[d]){"."!==f[d]&&(k=n(f[d++],g));d++;if(d+1===f.length||"("===f[d+1]&&")"===f[d+3]||"'"===f[d+
1]&&"'"===f[d+3])m=n(f[d],g),h=Math.pow(10,f[d].length),d++;if("("===f[d]&&")"===f[d+2]||"'"===f[d]&&"'"===f[d+2])l=n(f[d+1],g),q=Math.pow(10,f[d+1].length)-1,d+=3}else"/"===f[d+1]||":"===f[d+1]?(m=n(f[d],g),h=n(f[d+2],1),d+=3):"/"===f[d+3]&&" "===f[d+1]&&(k=n(f[d],g),m=n(f[d+2],g),h=n(f[d+4],1),d+=5);if(f.length<=d){g=e=l+q*(k*h+m);p=h*q;break}default:v()}if(!p)throw"DIV/0";c.s=0>g?-1:1;c.n=Math.abs(e);c.d=Math.abs(p)}function n(a,b){isNaN(a=parseInt(a,10))&&v();return a*b}function v(){throw"Invalid Param";
}function g(a,b){if(!(this instanceof g))return new g(a,b);k(a,b);g.REDUCE?a=u(c.d,c.n):a=1;this.s=c.s;this.n=c.n/a;this.d=c.d/a}var c={s:1,n:0,d:1};g.REDUCE=1;g.prototype={s:1,n:0,d:1,abs:function(){return new g(this.n,this.d)},neg:function(){return new g(-this.s*this.n,this.d)},add:function(a,b){k(a,b);return new g(this.s*this.n*c.d+c.s*this.d*c.n,this.d*c.d)},sub:function(a,b){k(a,b);return new g(this.s*this.n*c.d-c.s*this.d*c.n,this.d*c.d)},mul:function(a,b){k(a,b);return new g(this.s*c.s*this.n*
c.n,this.d*c.d)},div:function(a,b){k(a,b);return new g(this.s*c.s*this.n*c.d,this.d*c.n)},clone:function(){return new g(this)},mod:function(a,b){if(void 0===a)return new g(this.s*this.n%this.d,1);k(a,b);0===c.n*this.d&&g(0,0);return new g(this.s*c.d*this.n%(c.n*this.d),c.d*this.d)},gcd:function(a,b){k(a,b);return new g(u(c.n,this.n),c.d*this.d/u(c.d,this.d))},ceil:function(){return new g(Math.ceil(this.s*this.n/this.d),1)},floor:function(){return new g(Math.floor(this.s*this.n/this.d),1)},round:function(){return new g(Math.round(this.s*
this.n/this.d),1)},inverse:function(){return new g(this.s*this.d,this.n)},pow:function(a){var b=this.d,e=this.n;0>a?(this.d=Math.pow(e,-a),this.n=Math.pow(b,-a)):(this.d=Math.pow(b,a),this.n=Math.pow(e,a));0===a%2&&(this.s=1);return this},equals:function(a,b){k(a,b);return this.s*this.n*c.d===c.s*c.n*this.d},compare:function(a,b){k(a,b);var e=this.s*this.n*c.d-c.s*c.n*this.d;return(0<e)-(0>e)},divisible:function(a,b){k(a,b);return!!(c.n*this.d)&&!(this.n*c.d%(c.n*this.d))},valueOf:function(){return this.s*
this.n/this.d},toFraction:function(){var a,b="",e=this.n,c=this.d;0>this.s&&(b+="-");1===c?b+=e:(a=Math.floor(e/c),0<a&&(b=b+a+" ",e%=c),b+=e,b+="/",b+=c);return b},toLatex:function(){var a="",b=this.n,e=this.d;0>this.s&&(a+="-");1===e?a+=b:(a=a+"\\frac{"+b,a+="}{",a+=e,a+="}");return a},toString:function(){var a,b=this.n,e=this.d;g.REDUCE||(a=u(b,e),b/=a,e/=a);a=String(b).split("");var b=0,c=[~this.s?"":"-","",""],k="",n=x(e),m;a:{m=1;var l;l=n;for(var h=10,q=1;0<l;h=h*h%e,l>>=1)l&1&&(q=q*h%e);l=
q;for(h=0;300>h;h++){if(m===l){m=h;break a}m=10*m%e;l=10*l%e}m=0}l=-1;for(var h=1,q=10+n+m+a.length,d=0;d<q;d++,b*=10){d<a.length?b+=Number(a[d]):(h=2,l++);if(0<n)if(l===m)c[h]+=k+"(",k="";else if(l===n+m){c[h]+=k+")";break}b>=e?(c[h]+=k+(b/e|0),k="",b%=e):1<h?k+="0":c[h]&&(c[h]+="0")}c[0]+=c[1]||"0";return c[2]?c[0]+"."+c[2]:c[0]}};"function"===typeof define&&define.amd?define([],function(){return g}):"object"===typeof exports?module.exports=g:w.Fraction=g})(this);
(function(w){"use strict";function u(a,d){if(!a)return d;if(!d)return a;for(;;){a%=d;if(!a)return d;d%=a;if(!d)return a}}function x(a){for(;0===a%2;a/=2);for(;0===a%5;a/=5);if(1===a)return 0;for(var d=10%a,b=1;1!==d;b++)if(d=10*d%a,2E3<b)return 0;return b}function k(a,d){var b=0,m=1,l=1,g=0,p=0,n=0,h=1,q=1,e=0,f=1,k=1,r=1;if(void 0!==a&&null!==a)if(void 0!==d)b=a,m=d,l=b*m;else switch(typeof a){case "object":"d"in a&&"n"in a?(b=a.n,m=a.d,"s"in a&&(b*=a.s)):0 in a?(b=a[0],1 in a&&(m=a[1])):v();l=b*m;break;case "number":0>
a&&(l=a,a=-a);if(0===a%1)b=a;else if(0<a){1<=a&&(q=Math.pow(10,Math.floor(1+Math.log(a)/Math.LN10)),a/=q);for(;1E7>=f&&1E7>=r;)if(b=(e+k)/(f+r),a===b){1E7>=f+r?(b=e+k,m=f+r):r>f?(b=k,m=r):(b=e,m=f);break}else a>b?(e+=k,f+=r):(k+=e,r+=f),1E7<f?(b=k,m=r):(b=e,m=f);b*=q}break;case "string":f=a.match(/\d+|./g);"-"===f[e]?(l=-1,e++):"+"===f[e]&&e++;if(f.length===e+1)p=t(f[e++],l);else if("."===f[e+1]||"."===f[e]){"."!==f[e]&&(g=t(f[e++],l));e++;if(e+1===f.length||"("===f[e+1]&&")"===f[e+3]||"'"===f[e+
1]&&"'"===f[e+3])p=t(f[e],l),h=Math.pow(10,f[e].length),e++;if("("===f[e]&&")"===f[e+2]||"'"===f[e]&&"'"===f[e+2])n=t(f[e+1],l),q=Math.pow(10,f[e+1].length)-1,e+=3}else"/"===f[e+1]||":"===f[e+1]?(p=t(f[e],l),h=t(f[e+2],1),e+=3):"/"===f[e+3]&&" "===f[e+1]&&(g=t(f[e],l),p=t(f[e+2],l),h=t(f[e+4],1),e+=5);if(f.length<=e){l=b=n+q*(g*h+p);m=h*q;break}default:v()}if(!m)throw"DIV/0";c.s=0>l?-1:1;c.n=Math.abs(b);c.d=Math.abs(m)}function t(a,d){isNaN(a=parseInt(a,10))&&v();return a*d}function v(){throw"Invalid Param";
}function g(a,d){if(!(this instanceof g))return new g(a,d);k(a,d);g.REDUCE?a=u(c.d,c.n):a=1;this.s=c.s;this.n=c.n/a;this.d=c.d/a}var c={s:1,n:0,d:1};g.REDUCE=1;g.prototype={s:1,n:0,d:1,abs:function(){return new g(this.n,this.d)},neg:function(){return new g(-this.s*this.n,this.d)},add:function(a,d){k(a,d);return new g(this.s*this.n*c.d+c.s*this.d*c.n,this.d*c.d)},sub:function(a,d){k(a,d);return new g(this.s*this.n*c.d-c.s*this.d*c.n,this.d*c.d)},mul:function(a,d){k(a,d);return new g(this.s*c.s*this.n*
c.n,this.d*c.d)},div:function(a,d){k(a,d);return new g(this.s*c.s*this.n*c.d,this.d*c.n)},clone:function(){return new g(this)},mod:function(a,d){if(void 0===a)return new g(this.s*this.n%this.d,1);k(a,d);0===c.n*this.d&&g(0,0);return new g(this.s*c.d*this.n%(c.n*this.d),c.d*this.d)},gcd:function(a,d){k(a,d);return new g(u(c.n,this.n),c.d*this.d/u(c.d,this.d))},ceil:function(){return new g(Math.ceil(this.s*this.n/this.d),1)},floor:function(){return new g(Math.floor(this.s*this.n/this.d),1)},round:function(){return new g(Math.round(this.s*
this.n/this.d),1)},inverse:function(){return new g(this.s*this.d,this.n)},pow:function(a){var d=this.d,b=this.n;0>a?(this.d=Math.pow(b,-a),this.n=Math.pow(d,-a)):(this.d=Math.pow(d,a),this.n=Math.pow(b,a));0===a%2&&(this.s=1);return this},equals:function(a,d){k(a,d);return this.s*this.n*c.d===c.s*c.n*this.d},compare:function(a,d){k(a,d);var b=this.s*this.n*c.d-c.s*c.n*this.d;return(0<b)-(0>b)},divisible:function(a,d){k(a,d);return!!(c.n*this.d)&&!(this.n*c.d%(c.n*this.d))},valueOf:function(){return this.s*
this.n/this.d},toFraction:function(a){var d,b="",m=this.n,c=this.d;0>this.s&&(b+="-");1===c?b+=m:(a&&0<(d=Math.floor(m/c))&&(b=b+d+" ",m%=c),b+=m,b+="/",b+=c);return b},toLatex:function(a){var d,b="",c=this.n,g=this.d;0>this.s&&(b+="-");1===g?b+=c:(a&&0<(d=Math.floor(c/g))&&(b+=d,c%=g),b=b+"\\frac{"+c,b+="}{",b+=g,b+="}");return b},toString:function(){var a,d=this.n,b=this.d;g.REDUCE||(a=u(d,b),d/=a,b/=a);a=String(d).split("");var d=0,c=[~this.s?"":"-","",""],l="",k=x(b),p;a:{p=1;var n;n=k;for(var h=
10,q=1;0<n;h=h*h%b,n>>=1)n&1&&(q=q*h%b);n=q;for(h=0;300>h;h++){if(p===n){p=h;break a}p=10*p%b;n=10*n%b}p=0}n=-1;for(var h=1,q=10+k+p+a.length,e=0;e<q;e++,d*=10){e<a.length?d+=Number(a[e]):(h=2,n++);if(0<k)if(n===p)c[h]+=l+"(",l="";else if(n===k+p){c[h]+=l+")";break}d>=b?(c[h]+=l+(d/b|0),l="",d%=b):1<h?l+="0":c[h]&&(c[h]+="0")}c[0]+=c[1]||"0";return c[2]?c[0]+"."+c[2]:c[0]}};"function"===typeof define&&define.amd?define([],function(){return g}):"object"===typeof exports?module.exports=g:w.Fraction=
g})(this);
{
"name": "fraction.js",
"title": "fraction.js",
"version": "2.8.0",
"version": "2.9.0",
"homepage": "http://www.xarg.org/2014/03/precise-calculations-in-javascript/",

@@ -6,0 +6,0 @@ "bugs": "https://github.com/infusion/Fraction.js/issues",

@@ -269,2 +269,15 @@ # Fraction.js - ℚ in JavaSript

Attributes
===
The Fraction object allows direct access to the numerator, denominator and sign attributes. It is ensured that only the sign-attribute holds sign information so that a sign comparision is only necessary against this attribute.
```javascript
var f = new Fraction('-1/2');
console.log(f.n); // Numerator: 1
console.log(f.d); // Denominator: 2
console.log(f.s); // Sign: -1
```
Functions

@@ -357,10 +370,14 @@ ===

String toLatex()
String toLatex(excludeWhole=false)
---
Generates an exact LaTeX representation of the actual object. You can see a [live demo](http://www.xarg.org/2014/03/precise-calculations-in-javascript/) on my blog.
String toFraction()
The optional boolean parameter indicates if you want to exclude the whole part. "1 1/3" instead of "4/3"
String toFraction(excludeWhole=false)
---
Gets a string representation of the fraction
The optional boolean parameter indicates if you want to exclude the whole part. "1 1/3" instead of "4/3"
Fraction clone()

@@ -367,0 +384,0 @@ ---

@@ -983,3 +983,3 @@ var assert = require('assert');

var tmp = new Fraction("123.'3'");
assert.equal('123 1/3', tmp.toFraction());
assert.equal('370/3', tmp.toFraction());
});

@@ -990,3 +990,3 @@

var tmp = new Fraction("1.'3'");
assert.equal('1 1/3', tmp.toFraction());
assert.equal('4/3', tmp.toFraction());
});

@@ -993,0 +993,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc