Socket
Socket
Sign inDemoInstall

btrz-mathematics

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

btrz-mathematics - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

test-results/cobertura-coverage.xml

12

package.json
{
"name": "btrz-mathematics",
"version": "1.1.0",
"version": "1.2.0",
"description": "Betterez Mathematics",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test multi='xunit=test-results/xunit.xml spec=-' node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- --ui bdd -R mocha-multi -t 5000",
"test-w": "NODE_ENV=test node_modules/mocha/bin/mocha -w",
"publish": "publish"
"test": "NODE_ENV=test node_modules/mocha/bin/mocha --ui bdd -t 5000",
"test-w": "NODE_ENV=test node_modules/mocha/bin/mocha -w"
},

@@ -37,7 +36,4 @@ "repository": {

"chai": "^3.0.0",
"istanbul": "^0.4.1",
"mocha": "latest",
"mocha-multi": "latest",
"publish": "^0.5.0"
"mocha": "latest"
}
}
# btrz-mathematics
A mathematics library for node and crazy numbers

@@ -29,2 +29,21 @@ "use strict";

function isNegativeZero(x) {
return ( 1 / x ) === -Infinity;
}
function addOne(whole) {
const numWhole = Number(whole);
if (numWhole !== 0) {
return numWhole > 0 ? numWhole + 1 : numWhole - 1;
}
return isNegativeZero(whole) ? numWhole - 1 : numWhole + 1;
}
function wholePlusDigits(whole, digits = '00') {
if (Number(whole) !== 0) {
return `${whole}.${digits}`
}
return isNegativeZero(whole) && digits != 0 ? `-0.${digits}` : `0.${digits}`;
}
class Mathematics {

@@ -73,6 +92,6 @@

flip = cents.substr((digits), 1);
if ((flip < 5) || roundingPolicy === 'down') { return whole + '.00'; }
if ((flip < 5) || roundingPolicy === 'down') { return wholePlusDigits(whole); }
if ((flip > 4) || roundingPolicy === 'up') {
whole = Number(whole) + 1;
return whole + '.00';
whole = addOne(whole);
return wholePlusDigits(whole);
}

@@ -95,4 +114,4 @@ }

if (roundedCents === 100){
whole = Number(whole) + 1;
return whole + '.00';
whole = addOne(whole);
return wholePlusDigits(whole);
}

@@ -107,3 +126,3 @@ }

return whole + '.' + roundedCents;
return wholePlusDigits(whole, roundedCents);
}

@@ -110,0 +129,0 @@ }

@@ -112,2 +112,41 @@ "use strict";

});
describe("boder cases for positive and negative zeros", () => {
it("should round negative zero to 0.00 with precision 0", function () {
expect(mathematics.round(0.33, 0)).to.be.eql("0.00");
});
it("should round negative zero to 0.00 with precision 0", function () {
expect(mathematics.round(-0.33, 0)).to.be.eql("0.00");
});
it("should round to -1.00 with precision 2", function () {
expect(mathematics.round(-0.9974999999999999, 2)).to.be.eql("-1.00");
});
it("should round to -2.00 with precision 2", function () {
expect(mathematics.round(-1.9974999999999999, 2)).to.be.eql("-2.00");
});
it("should round to -1.10 with precision 2", function () {
expect(mathematics.round(-1.09725, 2)).to.be.eql("-1.10");
});
it("should round to -1.01 with precision 2", function () {
expect(mathematics.round(-1.009725, 2)).to.be.eql("-1.01");
});
it("should round to 0.00 with precision 2", function () {
expect(mathematics.round(0.00333, 2)).to.be.eql("0.00");
});
it("should round negative zero to 0.00 with precision 2", function () {
expect(mathematics.round(-0.00333, 2)).to.be.eql("0.00");
});
it("should round to same negative number with 5 digits", function () {
expect(mathematics.round(-0.02, 5)).to.be.eql("-0.02000");
});
});
});
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