diff options
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'], |