Skip to content

Commit

Permalink
Release v1.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gentooboontoo committed Dec 15, 2018
1 parent cb3540b commit 368d455
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 97 deletions.
6 changes: 6 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.7.3 / 2018-12-15
------------------

* Fix some inconsistent resulting units when multiplying or dividing
quantities (#94)

1.7.2 / 2018-03-31
------------------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and within browsers.

### Browser

Download [latest release v1.7.2](https://raw.github.com/gentooboontoo/js-quantities/v1.7.2/build/quantities.js)
Download [latest release v1.7.3](https://raw.github.com/gentooboontoo/js-quantities/v1.7.3/build/quantities.js)
or install it with Bower:

bower install js-quantities
Expand Down
2 changes: 1 addition & 1 deletion RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.2
1.7.3
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-quantities",
"version": "1.7.2",
"version": "1.7.3",
"description": "JavaScript library for quantity calculation and unit conversion",
"main": "./build/quantities.js",
"keywords": [
Expand Down
93 changes: 47 additions & 46 deletions build/quantities.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1484,9 +1484,9 @@ assign(Qty.prototype, {
if (op1.isCompatible(op2) && op1.signature !== 400) {
op2 = op2.to(op1);
}
var numden = cleanTerms(op1.numerator.concat(op2.numerator), op1.denominator.concat(op2.denominator));
var numdenscale = cleanTerms(op1.numerator, op1.denominator, op2.numerator, op2.denominator);

return Qty({"scalar": mulSafe(op1.scalar, op2.scalar), "numerator": numden[0], "denominator": numden[1]});
return Qty({"scalar": mulSafe(op1.scalar, op2.scalar, numdenscale[2]), "numerator": numdenscale[0], "denominator": numdenscale[1]});
},

div: function(other) {
Expand Down Expand Up @@ -1520,9 +1520,9 @@ assign(Qty.prototype, {
if (op1.isCompatible(op2) && op1.signature !== 400) {
op2 = op2.to(op1);
}
var numden = cleanTerms(op1.numerator.concat(op2.denominator), op1.denominator.concat(op2.numerator));
var numdenscale = cleanTerms(op1.numerator, op1.denominator, op2.denominator, op2.numerator);

return Qty({"scalar": op1.scalar / op2.scalar, "numerator": numden[0], "denominator": numden[1]});
return Qty({"scalar": mulSafe(op1.scalar, numdenscale[2]) / op2.scalar, "numerator": numdenscale[0], "denominator": numdenscale[1]});
},

// Returns a Qty that is the inverse of this Qty,
Expand All @@ -1537,70 +1537,71 @@ assign(Qty.prototype, {
}
});

function cleanTerms(num, den) {
num = num.filter(function(val) {
function cleanTerms(num1, den1, num2, den2) {
function notUnity(val) {
return val !== UNITY;
});
den = den.filter(function(val) {
return val !== UNITY;
});
}

num1 = num1.filter(notUnity);
num2 = num2.filter(notUnity);
den1 = den1.filter(notUnity);
den2 = den2.filter(notUnity);

var combined = {};

var k;
for (var i = 0; i < num.length; i++) {
if (PREFIX_VALUES[num[i]]) {
k = [num[i], num[i + 1]];
i++;
}
else {
k = num[i];
}
if (k && k !== UNITY) {
if (combined[k]) {
combined[k][0]++;
function combineTerms(terms, direction) {
var k;
var prefix;
var prefixValue;
for (var i = 0; i < terms.length; i++) {
if (PREFIX_VALUES[terms[i]]) {
k = terms[i + 1];
prefix = terms[i];
prefixValue = PREFIX_VALUES[prefix];
i++;
}
else {
combined[k] = [1, k];
}
}
}

for (var j = 0; j < den.length; j++) {
if (PREFIX_VALUES[den[j]]) {
k = [den[j], den[j + 1]];
j++;
}
else {
k = den[j];
}
if (k && k !== UNITY) {
if (combined[k]) {
combined[k][0]--;
k = terms[i];
prefix = null;
prefixValue = 1;
}
else {
combined[k] = [-1, k];
if (k && k !== UNITY) {
if (combined[k]) {
combined[k][0] += direction;
var combinedPrefixValue = combined[k][2] ? PREFIX_VALUES[combined[k][2]] : 1;
combined[k][direction === 1 ? 3 : 4] *= divSafe(prefixValue, combinedPrefixValue);
}
else {
combined[k] = [direction, k, prefix, 1, 1];
}
}
}
}

num = [];
den = [];
combineTerms(num1, 1);
combineTerms(den1, -1);
combineTerms(num2, 1);
combineTerms(den2, -1);

var num = [];
var den = [];
var scale = 1;

for (var prop in combined) {
if (combined.hasOwnProperty(prop)) {
var item = combined[prop];
var n;
if (item[0] > 0) {
for (n = 0; n < item[0]; n++) {
num.push(item[1]);
num.push(item[2] === null ? item[1] : [item[2], item[1]]);
}
}
else if (item[0] < 0) {
for (n = 0; n < -item[0]; n++) {
den.push(item[1]);
den.push(item[2] === null ? item[1] : [item[2], item[1]]);
}
}
scale *= divSafe(item[3], item[4]);
}
}

Expand All @@ -1619,7 +1620,7 @@ function cleanTerms(num, den) {
return a.concat(b);
}, []);

return [num, den];
return [num, den, scale];
}

assign(Qty.prototype, {
Expand Down Expand Up @@ -1990,6 +1991,6 @@ function simplify (units) {
});
}

Qty.version = "1.7.2";
Qty.version = "1.7.3";

export default Qty;
93 changes: 47 additions & 46 deletions build/quantities.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,9 +1490,9 @@ SOFTWARE.
if (op1.isCompatible(op2) && op1.signature !== 400) {
op2 = op2.to(op1);
}
var numden = cleanTerms(op1.numerator.concat(op2.numerator), op1.denominator.concat(op2.denominator));
var numdenscale = cleanTerms(op1.numerator, op1.denominator, op2.numerator, op2.denominator);

return Qty({"scalar": mulSafe(op1.scalar, op2.scalar), "numerator": numden[0], "denominator": numden[1]});
return Qty({"scalar": mulSafe(op1.scalar, op2.scalar, numdenscale[2]), "numerator": numdenscale[0], "denominator": numdenscale[1]});
},

div: function(other) {
Expand Down Expand Up @@ -1526,9 +1526,9 @@ SOFTWARE.
if (op1.isCompatible(op2) && op1.signature !== 400) {
op2 = op2.to(op1);
}
var numden = cleanTerms(op1.numerator.concat(op2.denominator), op1.denominator.concat(op2.numerator));
var numdenscale = cleanTerms(op1.numerator, op1.denominator, op2.denominator, op2.numerator);

return Qty({"scalar": op1.scalar / op2.scalar, "numerator": numden[0], "denominator": numden[1]});
return Qty({"scalar": mulSafe(op1.scalar, numdenscale[2]) / op2.scalar, "numerator": numdenscale[0], "denominator": numdenscale[1]});
},

// Returns a Qty that is the inverse of this Qty,
Expand All @@ -1543,70 +1543,71 @@ SOFTWARE.
}
});

function cleanTerms(num, den) {
num = num.filter(function(val) {
function cleanTerms(num1, den1, num2, den2) {
function notUnity(val) {
return val !== UNITY;
});
den = den.filter(function(val) {
return val !== UNITY;
});
}

num1 = num1.filter(notUnity);
num2 = num2.filter(notUnity);
den1 = den1.filter(notUnity);
den2 = den2.filter(notUnity);

var combined = {};

var k;
for (var i = 0; i < num.length; i++) {
if (PREFIX_VALUES[num[i]]) {
k = [num[i], num[i + 1]];
i++;
}
else {
k = num[i];
}
if (k && k !== UNITY) {
if (combined[k]) {
combined[k][0]++;
function combineTerms(terms, direction) {
var k;
var prefix;
var prefixValue;
for (var i = 0; i < terms.length; i++) {
if (PREFIX_VALUES[terms[i]]) {
k = terms[i + 1];
prefix = terms[i];
prefixValue = PREFIX_VALUES[prefix];
i++;
}
else {
combined[k] = [1, k];
}
}
}

for (var j = 0; j < den.length; j++) {
if (PREFIX_VALUES[den[j]]) {
k = [den[j], den[j + 1]];
j++;
}
else {
k = den[j];
}
if (k && k !== UNITY) {
if (combined[k]) {
combined[k][0]--;
k = terms[i];
prefix = null;
prefixValue = 1;
}
else {
combined[k] = [-1, k];
if (k && k !== UNITY) {
if (combined[k]) {
combined[k][0] += direction;
var combinedPrefixValue = combined[k][2] ? PREFIX_VALUES[combined[k][2]] : 1;
combined[k][direction === 1 ? 3 : 4] *= divSafe(prefixValue, combinedPrefixValue);
}
else {
combined[k] = [direction, k, prefix, 1, 1];
}
}
}
}

num = [];
den = [];
combineTerms(num1, 1);
combineTerms(den1, -1);
combineTerms(num2, 1);
combineTerms(den2, -1);

var num = [];
var den = [];
var scale = 1;

for (var prop in combined) {
if (combined.hasOwnProperty(prop)) {
var item = combined[prop];
var n;
if (item[0] > 0) {
for (n = 0; n < item[0]; n++) {
num.push(item[1]);
num.push(item[2] === null ? item[1] : [item[2], item[1]]);
}
}
else if (item[0] < 0) {
for (n = 0; n < -item[0]; n++) {
den.push(item[1]);
den.push(item[2] === null ? item[1] : [item[2], item[1]]);
}
}
scale *= divSafe(item[3], item[4]);
}
}

Expand All @@ -1625,7 +1626,7 @@ SOFTWARE.
return a.concat(b);
}, []);

return [num, den];
return [num, den, scale];
}

assign(Qty.prototype, {
Expand Down Expand Up @@ -1996,7 +1997,7 @@ SOFTWARE.
});
}

Qty.version = "1.7.2";
Qty.version = "1.7.3";

return Qty;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "./build/quantities.js",
"readmeFilename": "README.md",
"description": "JavaScript library for quantity calculation and unit conversion",
"version": "1.7.2",
"version": "1.7.3",
"homepage": "http://gentooboontoo.github.io/js-quantities/",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/quantities.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import "./quantities/predicates.js";
import "./quantities/conversion.js";
import "./quantities/format.js";

Qty.version = "1.7.2";
Qty.version = "1.7.3";

export default Qty;

0 comments on commit 368d455

Please sign in to comment.