aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRanger Harke <ranger.harke@autodesk.com>2013-09-19 17:09:10 -0400
committerRanger Harke <ranger.harke@autodesk.com>2013-09-19 17:09:10 -0400
commitb72b6d897250cc7624b66832f720ff3bed6823a6 (patch)
treeb5ee896cb45e24bab3114e018744a574e4577912
parente4678bed92f20ea0b5cd6fa2467cc2b0444511e0 (diff)
Fix bug with forced display of sign on negative integers
The negative sign was displayed twice.
-rw-r--r--src/library.js8
-rw-r--r--tests/printf/output.txt1
-rw-r--r--tests/printf/output_i64_1.txt1
-rw-r--r--tests/printf/test.c1
4 files changed, 5 insertions, 6 deletions
diff --git a/src/library.js b/src/library.js
index 0aaef0b2..995fa2ab 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2158,12 +2158,8 @@ LibraryManager.library = {
}
// Add sign if needed
- if (flagAlwaysSigned) {
- if (currArg < 0) {
- prefix = '-' + prefix;
- } else {
- prefix = '+' + prefix;
- }
+ if (flagAlwaysSigned && currArg >= 0) {
+ prefix = '+' + prefix;
}
// Move sign to prefix so we zero-pad after the sign
diff --git a/tests/printf/output.txt b/tests/printf/output.txt
index 0f59d9fc..7ca4d88c 100644
--- a/tests/printf/output.txt
+++ b/tests/printf/output.txt
@@ -5,6 +5,7 @@ Characters: a A
Decimals: 1977 650000 12 4
Preceding with blanks: 1977 -1977
Preceding with zeros: 0000001977 -000001977
+Force sign: +1977 -1977 +1977 -1977
Some different radixes: 100 64 144 0x64 0144
floats: 3.14 +3e+00 3.141600E+00 00003.14
negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14
diff --git a/tests/printf/output_i64_1.txt b/tests/printf/output_i64_1.txt
index ca03386f..9cd8ed98 100644
--- a/tests/printf/output_i64_1.txt
+++ b/tests/printf/output_i64_1.txt
@@ -5,6 +5,7 @@ Characters: a A
Decimals: 1977 650000 12 4
Preceding with blanks: 1977 -1977
Preceding with zeros: 0000001977 -000001977
+Force sign: +1977 -1977 +1977 -1977
Some different radixes: 100 64 144 0x64 0144
floats: 3.14 +3e+00 3.141600E+00 00003.14
negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14
diff --git a/tests/printf/test.c b/tests/printf/test.c
index c5f159f1..b01a99db 100644
--- a/tests/printf/test.c
+++ b/tests/printf/test.c
@@ -10,6 +10,7 @@ int main() {
printf("Decimals: %d %ld %lld %d\n", 1977, 650000L, 12LL, 4);
printf("Preceding with blanks: %10d %10d\n", 1977, -1977);
printf("Preceding with zeros: %010d %010d\n", 1977, -1977);
+ printf("Force sign: %+d %+d %+6d %+6d\n", 1977, -1977, 1977, -1977);
printf("Some different radixes: %d %x %o %#x %#o\n", 100, 100, 100, 100, 100);
printf("floats: %4.2f %+.0e %E %08.2f\n", 3.1416, 3.1416, 3.1416, 3.1416);
printf("negative floats: %4.2f %+.0e %E %08.2f\n", -3.1416, -3.1416, -3.1416, -3.1416);