Permalink
Browse files

added test for negative zero. I need to simplify all the floatpoint s…

…tuff now that I know how to test for negative zero. How embarrassing... :)
  • Loading branch information...
1 parent 986cf3e commit 2c6ddbff9e31db6bebacaf8aaa284f2f4adabb1d Danny Yoo committed Feb 23, 2011
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/js-numbers.js
View
@@ -1574,7 +1574,7 @@ if (typeof(exports) !== 'undefined') {
// Negative zero is a distinguished value representing -0.0.
// There should only be one instance for -0.0.
- var NEGATIVE_ZERO = new FloatPoint(0);
+ var NEGATIVE_ZERO = new FloatPoint(-0.0);
var INEXACT_ZERO = new FloatPoint(0.0);
FloatPoint.pi = new FloatPoint(Math.PI);
@@ -1590,6 +1590,12 @@ if (typeof(exports) !== 'undefined') {
return FloatPoint.inf;
} else if (n === Number.NEGATIVE_INFINITY) {
return FloatPoint.neginf;
+ } else if (n === 0) {
+ if ((1/n) === -Infinity) {
+ return NEGATIVE_ZERO;
+ } else {
+ return INEXACT_ZERO;
+ }
}
return new FloatPoint(n);
};

0 comments on commit 2c6ddbf

Please sign in to comment.