diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-19 20:04:38 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-19 20:04:38 -0700 |
commit | bcbce4709178f424c26564f44a9ae499173d74fa (patch) | |
tree | 23818445fa5483bc7afde2aeffd1c697c97b2ec4 /src/library.js | |
parent | 7eda11db7c57aa4d231e468f87ded2d703034225 (diff) |
handle negative zero; fixes #921
Diffstat (limited to 'src/library.js')
-rw-r--r-- | src/library.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/library.js b/src/library.js index 793a78d7..382c21ad 100644 --- a/src/library.js +++ b/src/library.js @@ -2642,7 +2642,7 @@ LibraryManager.library = { // format: A pointer to the format string. // varargs: A pointer to the start of the arguments list. // Returns the resulting string string as a character array. - _formatString__deps: ['strlen'], + _formatString__deps: ['strlen', '_reallyNegative'], _formatString: function(format, varargs) { var textIndex = format; var argIndex = 0; @@ -2897,7 +2897,6 @@ LibraryManager.library = { // Float. var currArg = getNextArg('double'); var argText; - if (isNaN(currArg)) { argText = 'nan'; flagZeroPad = false; @@ -2932,6 +2931,9 @@ LibraryManager.library = { } } else if (next == {{{ charCode('f') }}} || next == {{{ charCode('F') }}}) { argText = currArg.toFixed(effectivePrecision); + if (currArg === 0 && __reallyNegative(currArg)) { + argText = '-' + argText; + } } var parts = argText.split('e'); @@ -5478,9 +5480,14 @@ LibraryManager.library = { return isNaN(x); }, __isnan: 'isnan', + + _reallyNegative: function(x) { + return x < 0 || (x === 0 && (1/x) === -Infinity); + }, + + copysign__deps: ['_reallyNegative'], copysign: function(a, b) { - if (a < 0 === b < 0) return a; - return -a; + return __reallyNegative(a) === __reallyNegative(b) ? a : -a; }, copysignf: 'copysign', __signbit__deps: ['copysign'], |