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.1.2 to 4.1.3

37

bigfraction.js
/**
* @license Fraction.js v4.1.2 23/05/2021
* @license Fraction.js v4.1.3 23/05/2021
* https://www.xarg.org/2014/03/rational-numbers-in-javascript/

@@ -119,3 +119,3 @@ *

if (n > 1)
factors[n] = (factors[n] || C_ZERO) + C_ONE;
factors[n] = (factors[n] || C_ZERO) + C_ONE;
} else {

@@ -664,5 +664,7 @@ factors[num] = (factors[num] || C_ZERO) + C_ONE;

places = 10 ** Number(places || 0);
places = C_TEN ** BigInt(places || 0);
return new Fraction(Math.ceil(places * Number(this["s"] * this["n"]) / Number(this["d"])), places);
return new Fraction(this["s"] * places * this["n"] / this["d"] +
(places * this["n"] % this["d"] > C_ZERO && this["s"] >= C_ZERO ? C_ONE : C_ZERO),
places);
},

@@ -677,5 +679,7 @@

places = 10 ** Number(places || 0);
places = C_TEN ** BigInt(places || 0);
return new Fraction(Math.floor(places * Number(this["s"] * this["n"]) / Number(this["d"])), places);
return new Fraction(this["s"] * places * this["n"] / this["d"] -
(places * this["n"] % this["d"] > C_ZERO && this["s"] < C_ZERO ? C_ONE : C_ZERO),
places);
},

@@ -690,5 +694,22 @@

places = 10 ** Number(places || 0);
places = C_TEN ** BigInt(places || 0);
return new Fraction(Math.round(places * Number(this["s"] * this["n"]) / Number(this["d"])), places);
/* Derivation:
s >= 0:
round(n / d) = trunc(n / d) + (n % d) / d >= 0.5 ? 1 : 0
= trunc(n / d) + 2(n % d) >= d ? 1 : 0
s < 0:
round(n / d) =-trunc(n / d) - (n % d) / d > 0.5 ? 1 : 0
=-trunc(n / d) - 2(n % d) > d ? 1 : 0
=>:
round(s * n / d) = s * trunc(n / d) + s * (C + 2(n % d) > d ? 1 : 0)
where C = s >= 0 ? 1 : 0, to fix the >= for the positve case.
*/
return new Fraction(this["s"] * places * this["n"] / this["d"] +
this["s"] * ((this["s"] >= C_ZERO ? C_ONE : C_ZERO) + C_TWO * (places * this["n"] % this["d"]) > this["d"] ? C_ONE : C_ZERO),
places);
},

@@ -695,0 +716,0 @@

/**
* @license Fraction.js v4.1.2 23/05/2021
* @license Fraction.js v4.1.3 23/05/2021
* https://www.xarg.org/2014/03/rational-numbers-in-javascript/

@@ -4,0 +4,0 @@ *

/*
Fraction.js v4.1.2 23/05/2021
Fraction.js v4.1.3 23/05/2021
https://www.xarg.org/2014/03/rational-numbers-in-javascript/

@@ -4,0 +4,0 @@

{
"name": "fraction.js",
"title": "fraction.js",
"version": "4.1.2",
"version": "4.1.3",
"homepage": "https://www.xarg.org/2014/03/rational-numbers-in-javascript/",

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

@@ -464,2 +464,9 @@ # Fraction.js - ℚ in JavaScript

Using Fraction.js with TypeScript
===
```js
import Fraction from "fraction.js";
console.log(Fraction("123/456"));
```
Coding Style

@@ -466,0 +473,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