Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing bug in FloatPoint.prototype.subtract: it wasn't comparing NEGA…

…TIVE_ZERO properly.
  • Loading branch information...
commit 46fc2190cd62661ec000cb6ef7ca275ead0bd195 1 parent 2d1fd44
Danny Yoo authored
Showing with 11 additions and 10 deletions.
  1. +3 −3 src/js-numbers.js
  2. +8 −7 test/tests.js
6 src/js-numbers.js
View
@@ -1722,10 +1722,10 @@ if (typeof(exports) !== 'undefined') {
if (this.isFinite() && other.isFinite()) {
var result = this.n - other.n;
if (result === 0.0) {
- if (other.n === NEGATIVE_ZERO) {
+ if (other === NEGATIVE_ZERO) {
return FloatPoint.makeInstance(result);
}
- else if (this.n === NEGATIVE_ZERO) {
+ else if (this === NEGATIVE_ZERO) {
return NEGATIVE_ZERO;
}
}
@@ -1743,9 +1743,9 @@ if (typeof(exports) !== 'undefined') {
} else { // other.isFinite()
return this;
}
-
};
+
FloatPoint.prototype.negate = function() {
if (this === NEGATIVE_ZERO) {
return FloatPoint.makeInstance(0);
15 test/tests.js
View
@@ -1510,13 +1510,14 @@ describe('subtract', {
'negative zero': function() {
assertTrue(eqv(makeFloat(0.0),
subtract(negative_zero, negative_zero)));
- assertTrue(eqv(makeFloat(0.0),
- subtract(makeFloat(0), negative_zero)));
- assertTrue(eqv(negative_zero,
- subtract(negative_zero, makeFloat(0))));
-
- assertTrue(eqv(makeComplex(negative_zero, negative_zero),
- subtract(0, makeComplex(makeFloat(0), makeFloat(0)))));
+ assertTrue(eqv(makeFloat(0.0),
+ subtract(makeFloat(0), negative_zero)));
+ assertTrue(eqv(negative_zero,
+ subtract(negative_zero, 0)));
+ assertTrue(eqv(negative_zero,
+ subtract(negative_zero, makeFloat(0))));
+ assertTrue(eqv(makeComplex(negative_zero, negative_zero),
+ subtract(0, makeComplex(makeFloat(0), makeFloat(0)))));
},
'floating / complex' : function() {
Please sign in to comment.
Something went wrong with that request. Please try again.