Skip to content

Commit

Permalink
fixing bug in FloatPoint.prototype.subtract: it wasn't comparing NEGA…
Browse files Browse the repository at this point in the history
…TIVE_ZERO properly.
  • Loading branch information
Danny Yoo committed Dec 10, 2010
1 parent 2d1fd44 commit 46fc219
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/js-numbers.js
Expand Up @@ -1722,10 +1722,10 @@ if (typeof(exports) !== 'undefined') {
if (this.isFinite() && other.isFinite()) { if (this.isFinite() && other.isFinite()) {
var result = this.n - other.n; var result = this.n - other.n;
if (result === 0.0) { if (result === 0.0) {
if (other.n === NEGATIVE_ZERO) { if (other === NEGATIVE_ZERO) {
return FloatPoint.makeInstance(result); return FloatPoint.makeInstance(result);
} }
else if (this.n === NEGATIVE_ZERO) { else if (this === NEGATIVE_ZERO) {
return NEGATIVE_ZERO; return NEGATIVE_ZERO;
} }
} }
Expand All @@ -1743,9 +1743,9 @@ if (typeof(exports) !== 'undefined') {
} else { // other.isFinite() } else { // other.isFinite()
return this; return this;
} }

}; };



FloatPoint.prototype.negate = function() { FloatPoint.prototype.negate = function() {
if (this === NEGATIVE_ZERO) { if (this === NEGATIVE_ZERO) {
return FloatPoint.makeInstance(0); return FloatPoint.makeInstance(0);
Expand Down
15 changes: 8 additions & 7 deletions test/tests.js
Expand Up @@ -1510,13 +1510,14 @@ describe('subtract', {
'negative zero': function() { 'negative zero': function() {
assertTrue(eqv(makeFloat(0.0), assertTrue(eqv(makeFloat(0.0),
subtract(negative_zero, negative_zero))); subtract(negative_zero, negative_zero)));
assertTrue(eqv(makeFloat(0.0), assertTrue(eqv(makeFloat(0.0),
subtract(makeFloat(0), negative_zero))); subtract(makeFloat(0), negative_zero)));
assertTrue(eqv(negative_zero, assertTrue(eqv(negative_zero,
subtract(negative_zero, makeFloat(0)))); subtract(negative_zero, 0)));

assertTrue(eqv(negative_zero,
assertTrue(eqv(makeComplex(negative_zero, negative_zero), subtract(negative_zero, makeFloat(0))));
subtract(0, makeComplex(makeFloat(0), makeFloat(0))))); assertTrue(eqv(makeComplex(negative_zero, negative_zero),
subtract(0, makeComplex(makeFloat(0), makeFloat(0)))));
}, },


'floating / complex' : function() { 'floating / complex' : function() {
Expand Down

0 comments on commit 46fc219

Please sign in to comment.