Socket
Socket
Sign inDemoInstall

fraction.js

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fraction.js - npm Package Compare versions

Comparing version 4.0.8 to 4.0.9

2

bower.json
{
"name": "fraction.js",
"main": "fraction.js",
"version": "4.0.8",
"version": "4.0.9",
"homepage": "http://www.xarg.org/2014/03/rational-numbers-in-javascript/",

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

/**
* @license Fraction.js v4.0.8 09/09/2015
* @license Fraction.js v4.0.9 09/09/2015
* http://www.xarg.org/2014/03/rational-numbers-in-javascript/

@@ -765,3 +765,3 @@ *

**/
'toString': function() {
'toString': function(dec) {

@@ -782,3 +782,3 @@ var g;

var dec = 15; // 15 = decimal places when no repitation
dec = dec || 15; // 15 = decimal places when no repitation

@@ -785,0 +785,0 @@ var cycLen = cycleLen(N, D); // Cycle length

/*
Fraction.js v4.0.8 09/09/2015
Fraction.js v4.0.9 09/09/2015
http://www.xarg.org/2014/03/rational-numbers-in-javascript/

@@ -8,12 +8,12 @@

*/
(function(w){function k(a,c){var d=0,l=1,h=1,e=0,k=0,p=0,t=1,q=1,f=0,g=1,r=1,n=1;if(void 0!==a&&null!==a)if(void 0!==c)d=a,l=c,h=d*l;else switch(typeof a){case "object":"d"in a&&"n"in a?(d=a.n,l=a.d,"s"in a&&(d*=a.s)):0 in a?(d=a[0],1 in a&&(l=a[1])):u();h=d*l;break;case "number":0>a&&(h=a,a=-a);if(0===a%1)d=a;else if(0<a){1<=a&&(q=Math.pow(10,Math.floor(1+Math.log(a)/Math.LN10)),a/=q);for(;1E7>=g&&1E7>=n;)if(d=(f+r)/(g+n),a===d){1E7>=g+n?(d=f+r,l=g+n):n>g?(d=r,l=n):(d=f,l=g);break}else a>d?(f+=r,
g+=n):(r+=f,n+=g),1E7<g?(d=r,l=n):(d=f,l=g);d*=q}else if(isNaN(a)||isNaN(c))l=d=NaN;break;case "string":g=a.match(/\d+|./g);null===g&&u();"-"===g[f]?(h=-1,f++):"+"===g[f]&&f++;if(g.length===f+1)k=m(g[f++],h);else if("."===g[f+1]||"."===g[f]){"."!==g[f]&&(e=m(g[f++],h));f++;if(f+1===g.length||"("===g[f+1]&&")"===g[f+3]||"'"===g[f+1]&&"'"===g[f+3])k=m(g[f],h),t=Math.pow(10,g[f].length),f++;if("("===g[f]&&")"===g[f+2]||"'"===g[f]&&"'"===g[f+2])p=m(g[f+1],h),q=Math.pow(10,g[f+1].length)-1,f+=3}else"/"===
g[f+1]||":"===g[f+1]?(k=m(g[f],h),t=m(g[f+2],1),f+=3):"/"===g[f+3]&&" "===g[f+1]&&(e=m(g[f],h),k=m(g[f+2],h),t=m(g[f+4],1),f+=5);if(g.length<=f){l=t*q;h=d=p+l*e+q*k;break}default:u()}if(0===l)throw new x;b.s=0>h?-1:1;b.n=Math.abs(d);b.d=Math.abs(l)}function v(a){function c(){var c=Error.apply(this,arguments);c.name=this.name=a;this.stack=c.stack;this.message=c.message}function d(){}d.prototype=Error.prototype;c.prototype=new d;return c}function m(a,c){isNaN(a=parseInt(a,10))&&u();return a*c}function u(){throw new y;
}function p(a,c){if(!a)return c;if(!c)return a;for(;;){a%=c;if(!a)return c;c%=a;if(!c)return a}}function e(a,c){if(!(this instanceof e))return new e(a,c);k(a,c);a=e.REDUCE?p(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},x=e.DivisionByZero=v("DivisionByZero"),y=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(p(b.n,this.n)*p(b.d,this.d),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,p(b.n,this.n)*p(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(0<d)-(0>d)},simplify:function(a){function c(a){return 1===a.length?new e(a[0]):c(a.slice(1)).inverse().add(a[0])}
if(isNaN(this.n)||isNaN(this.d))return this;var d=this.abs().toContinued();a=a||.001;for(var l=0;l<d.length;l++){var b=c(d.slice(0,l+1));if(b.sub(this.abs()).abs().valueOf()<a)return b.mul(this.s)}return this},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="",l=this.n,b=this.d;0>this.s&&(d+="-");1===b?d+=l:(a&&0<(c=Math.floor(l/b))&&(d=d+c+" ",l%=b),d=d+l+"/",d+=b);return d},toLatex:function(a){var c,
d="",b=this.n,e=this.d;0>this.s&&(d+="-");1===e?d+=b:(a&&0<(c=Math.floor(b/e))&&(d+=c,b%=e),d=d+"\\frac{"+b+"}{"+e,d+="}");return d},toContinued:function(){var a=this.n,c=this.d,d=[];if(isNaN(this.n)||isNaN(this.d))return d;do{d.push(Math.floor(a/c));var b=a%c;a=c;c=b}while(1!==a);return d},toString:function(){var a=this.n,c=this.d;if(isNaN(a)||isNaN(c))return"NaN";if(!e.REDUCE){var d=p(a,c);a/=d;c/=d}a:{for(d=c;0===d%2;d/=2);for(;0===d%5;d/=5);if(1===d)d=0;else{for(var b=10%d,h=1;1!==b;h++)if(b=
10*b%d,2E3<h){d=0;break a}d=h}}a:{b=1;h=10;for(var k=d,m=1;0<k;h=h*h%c,k>>=1)k&1&&(m=m*h%c);h=m;for(k=0;300>k;k++){if(b===h){h=k;break a}b=10*b%c;h=10*h%c}h=0}b=-1===this.s?"-":"";b+=a/c|0;(a=a%c*10)&&(b+=".");if(d){for(;h--;)b+=a/c|0,a%=c,a*=10;for(b+="(";d--;)b+=a/c|0,a%=c,a*=10;b+=")"}else for(d=15;a&&d--;)b+=a/c|0,a%=c,a*=10;return b}};"function"===typeof define&&define.amd?define([],function(){return e}):"object"===typeof exports?(Object.defineProperty(exports,"__esModule",{value:!0}),e["default"]=
e,e.Fraction=e,module.exports=e):w.Fraction=e})(this);
(function(x){function l(a,b){var c=0,k=1,h=1,e=0,u=0,l=0,p=1,r=1,f=0,g=1,t=1,q=1;if(void 0!==a&&null!==a)if(void 0!==b)c=a,k=b,h=c*k;else switch(typeof a){case "object":"d"in a&&"n"in a?(c=a.n,k=a.d,"s"in a&&(c*=a.s)):0 in a?(c=a[0],1 in a&&(k=a[1])):v();h=c*k;break;case "number":0>a&&(h=a,a=-a);if(0===a%1)c=a;else if(0<a){1<=a&&(r=Math.pow(10,Math.floor(1+Math.log(a)/Math.LN10)),a/=r);for(;1E7>=g&&1E7>=q;)if(c=(f+t)/(g+q),a===c){1E7>=g+q?(c=f+t,k=g+q):q>g?(c=t,k=q):(c=f,k=g);break}else a>c?(f+=t,
g+=q):(t+=f,q+=g),1E7<g?(c=t,k=q):(c=f,k=g);c*=r}else if(isNaN(a)||isNaN(b))k=c=NaN;break;case "string":g=a.match(/\d+|./g);null===g&&v();"-"===g[f]?(h=-1,f++):"+"===g[f]&&f++;if(g.length===f+1)u=n(g[f++],h);else if("."===g[f+1]||"."===g[f]){"."!==g[f]&&(e=n(g[f++],h));f++;if(f+1===g.length||"("===g[f+1]&&")"===g[f+3]||"'"===g[f+1]&&"'"===g[f+3])u=n(g[f],h),p=Math.pow(10,g[f].length),f++;if("("===g[f]&&")"===g[f+2]||"'"===g[f]&&"'"===g[f+2])l=n(g[f+1],h),r=Math.pow(10,g[f+1].length)-1,f+=3}else"/"===
g[f+1]||":"===g[f+1]?(u=n(g[f],h),p=n(g[f+2],1),f+=3):"/"===g[f+3]&&" "===g[f+1]&&(e=n(g[f],h),u=n(g[f+2],h),p=n(g[f+4],1),f+=5);if(g.length<=f){k=p*r;h=c=l+k*e+r*u;break}default:v()}if(0===k)throw new y;d.s=0>h?-1:1;d.n=Math.abs(c);d.d=Math.abs(k)}function w(a){function b(){var b=Error.apply(this,arguments);b.name=this.name=a;this.stack=b.stack;this.message=b.message}function c(){}c.prototype=Error.prototype;b.prototype=new c;return b}function n(a,b){isNaN(a=parseInt(a,10))&&v();return a*b}function v(){throw new z;
}function p(a,b){if(!a)return b;if(!b)return a;for(;;){a%=b;if(!a)return b;b%=a;if(!b)return a}}function e(a,b){if(!(this instanceof e))return new e(a,b);l(a,b);a=e.REDUCE?p(d.d,d.n):1;this.s=d.s;this.n=d.n/a;this.d=d.d/a}var d={s:1,n:0,d:1},y=e.DivisionByZero=w("DivisionByZero"),z=e.InvalidParameter=w("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,b){l(a,b);return new e(this.s*
this.n*d.d+d.s*this.d*d.n,this.d*d.d)},sub:function(a,b){l(a,b);return new e(this.s*this.n*d.d-d.s*this.d*d.n,this.d*d.d)},mul:function(a,b){l(a,b);return new e(this.s*d.s*this.n*d.n,this.d*d.d)},div:function(a,b){l(a,b);return new e(this.s*d.s*this.n*d.d,this.d*d.n)},clone:function(){return new e(this)},mod:function(a,b){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);l(a,b);0===d.n&&0===this.d&&e(0,0);return new e(this.s*d.d*this.n%(d.n*this.d),
d.d*this.d)},gcd:function(a,b){l(a,b);return new e(p(d.n,this.n)*p(d.d,this.d),d.d*this.d)},lcm:function(a,b){l(a,b);return 0===d.n&&0===this.n?new e:new e(d.n*this.n,p(d.n,this.n)*p(d.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,b){l(a,b);return this.s*this.n*d.d===d.s*d.n*this.d},compare:function(a,b){l(a,b);var c=this.s*this.n*d.d-d.s*d.n*this.d;return(0<c)-(0>c)},simplify:function(a){function b(a){return 1===a.length?new e(a[0]):b(a.slice(1)).inverse().add(a[0])}
if(isNaN(this.n)||isNaN(this.d))return this;var c=this.abs().toContinued();a=a||.001;for(var k=0;k<c.length;k++){var h=b(c.slice(0,k+1));if(h.sub(this.abs()).abs().valueOf()<a)return h.mul(this.s)}return this},divisible:function(a,b){l(a,b);return!(!(d.n*this.d)||this.n*d.d%(d.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(a){var b,c="",k=this.n,e=this.d;0>this.s&&(c+="-");1===e?c+=k:(a&&0<(b=Math.floor(k/e))&&(c=c+b+" ",k%=e),c=c+k+"/",c+=e);return c},toLatex:function(a){var b,
c="",e=this.n,d=this.d;0>this.s&&(c+="-");1===d?c+=e:(a&&0<(b=Math.floor(e/d))&&(c+=b,e%=d),c=c+"\\frac{"+e+"}{"+d,c+="}");return c},toContinued:function(){var a=this.n,b=this.d,c=[];if(isNaN(this.n)||isNaN(this.d))return c;do{c.push(Math.floor(a/b));var e=a%b;a=b;b=e}while(1!==a);return c},toString:function(a){var b=this.n,c=this.d;if(isNaN(b)||isNaN(c))return"NaN";if(!e.REDUCE){var d=p(b,c);b/=d;c/=d}a:{for(d=c;0===d%2;d/=2);for(;0===d%5;d/=5);if(1===d)d=0;else{for(var h=10%d,m=1;1!==h;m++)if(h=
10*h%d,2E3<m){d=0;break a}d=m}}a:{h=1;m=10;for(var l=d,n=1;0<l;m=m*m%c,l>>=1)l&1&&(n=n*m%c);m=n;for(l=0;300>l;l++){if(h===m){m=l;break a}h=10*h%c;m=10*m%c}m=0}h=-1===this.s?"-":"";h+=b/c|0;(b=b%c*10)&&(h+=".");if(d){for(a=m;a--;)h+=b/c|0,b%=c,b*=10;h+="(";for(a=d;a--;)h+=b/c|0,b%=c,b*=10;h+=")"}else for(a=a||15;b&&a--;)h+=b/c|0,b%=c,b*=10;return h}};"function"===typeof define&&define.amd?define([],function(){return e}):"object"===typeof exports?(Object.defineProperty(exports,"__esModule",{value:!0}),
e["default"]=e,e.Fraction=e,module.exports=e):x.Fraction=e})(this);
{
"name": "fraction.js",
"title": "fraction.js",
"version": "4.0.8",
"version": "4.0.9",
"homepage": "http://www.xarg.org/2014/03/rational-numbers-in-javascript/",

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

@@ -107,3 +107,3 @@ # Fraction.js - ℚ in JavaSript

console.log(n + "\t" + a.n + "/" + a.d + "\t" + b.n + "/" + b.d + "\t" + c.n + "/" + c.d + "\t" + x);
console.log(n + "\t" + a + "\t" + b + "\t" + c + "\t" + x);

@@ -376,5 +376,5 @@ if (c.add(2).pow(2) < 5) {

String toString()
String toString([significantPlaces=15])
---
Generates an exact string representation of the actual object, including repeating decimal places of any length.
Generates an exact string representation of the actual object. For repeated decimal places all digits are collected within brackets, like `1/3 = "0.(3)"`. For all other numbers, up to `decimalPlaces` significant digits are collected - which includes trailing zeros if the number is getting truncated. `1/2 = "0.5" of course.

@@ -381,0 +381,0 @@ **Note:** As `valueOf()` and `toString()` are provided, `toString()` is only called implicitly in a real string context. Using the plus-operator like `"123" + new Fraction` will call valueOf(), because JavaScript tries to combine two primitives first and concatenates them later, as string will be the more dominant type. `alert(new Fraction)` or `String(new Fraction)` on the other hand will do what you expect. If you really want to have control, you should call `toString()` or `valueOf()` explicitly!

@@ -1186,2 +1186,32 @@ var assert = require('assert');

expect: "0"
}, {
label: "6869570742453802/5329686054127205",
set: "6869570742453802/5329686054127205",
fn: "neg",
param: 0,
expect: "-1.288925965373540"
}, {
label: "686970702/53212205",
set: "686970702/53212205",
fn: "neg",
param: 0,
expect: "-12.910021338149772"
}, {
label: "1/3000000000000000",
set: "1/3000000000000000",
fn: "add",
param: 0,
expect: "0.000000000000000(3)"
}, {
label: "toString(15) .0000000000000003",
set: ".0000000000000003",
fn: "toString",
param: 15,
expect: "0.000000000000000"
}, {
label: "toString(16) .0000000000000003",
set: ".0000000000000003",
fn: "toString",
param: 16,
expect: "0.0000000000000003"
}

@@ -1188,0 +1218,0 @@ ];

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc