Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixing definition of complex's isReal, isRational, and isInteger so i…

…t uses exactness
  • Loading branch information...
commit 70c84fc2c2fbeeebec9f6e22ad0b697f5199c6bb 1 parent d3bf179
Danny Yoo authored
Showing with 7 additions and 3 deletions.
  1. +3 −3 src/js-numbers.js
  2. +4 −0 test/tests.js
View
6 src/js-numbers.js
@@ -2020,12 +2020,12 @@ if (typeof(exports) !== 'undefined') {
Complex.prototype.isRational = function() {
- return isRational(this.r) && equals(this.i, 0);
+ return isRational(this.r) && eqv(this.i, 0);
};
Complex.prototype.isInteger = function() {
return (isInteger(this.r) &&
- equals(this.i, 0));
+ eqv(this.i, 0));
};
Complex.prototype.toExact = function() {
@@ -2190,7 +2190,7 @@ if (typeof(exports) !== 'undefined') {
};
Complex.prototype.isReal = function(){
- return equals(this.i, 0);
+ return eqv(this.i, 0);
};
Complex.prototype.integerSqrt = function() {
View
4 test/tests.js
@@ -646,6 +646,7 @@ describe('isRational', {
assertFalse(isRational(makeComplex(nan, 0)));
assertFalse(isRational(makeComplex(0, 1)));
assertFalse(isRational(makeComplex(0, negative_inf)));
+ assertFalse(isRational(makeComplex(makeFloat(0), makeFloat(0))));
},
'others': function() {
@@ -704,6 +705,8 @@ describe('isReal', {
assertFalse(isReal(makeComplex(0, negative_inf)));
assertFalse(isReal(makeComplex(pi, inf)));
assertFalse(isReal(makeComplex(234, nan)));
+ assertFalse(isReal(makeComplex(makeFloat(3),
+ makeFloat(0))));
},
'others': function() {
@@ -866,6 +869,7 @@ describe('isInteger', {
'complex': function() {
assertTrue(isInteger(makeComplex(42, 0)));
+ assertFalse(isInteger(makeComplex(makeFloat(42), makeFloat(0))));
assertFalse(isInteger(makeComplex(42, 42)));
assertFalse(isInteger(i));
assertFalse(isInteger(negative_i));

0 comments on commit 70c84fc

Please sign in to comment.
Something went wrong with that request. Please try again.