diff options
author | kripken <alonzakai@gmail.com> | 2011-06-28 18:26:18 -0700 |
---|---|---|
committer | kripken <alonzakai@gmail.com> | 2011-06-28 18:26:18 -0700 |
commit | 70edb25e68b311d4cdfc33463c9eb42793cd39ca (patch) | |
tree | d9032076d6c239f7b9d5efcdbdf321b2d272fa14 | |
parent | 145c2f66d979cb402558121e5e2aad3ebf1a8a2a (diff) | |
parent | 6fe80d00d655a03afadf8b4d19d99660c9eab7a0 (diff) |
Merge pull request #37 from max99x/master
Printf/_formatString polish
-rw-r--r-- | src/library.js | 162 | ||||
-rw-r--r-- | tests/printf/output.txt | 266 | ||||
-rw-r--r-- | tests/printf/test.c | 267 |
3 files changed, 646 insertions, 49 deletions
diff --git a/src/library.js b/src/library.js index 54256c44..284f093d 100644 --- a/src/library.js +++ b/src/library.js @@ -65,9 +65,6 @@ var Library = { _formatString__deps: ['$STDIO', 'isdigit'], _formatString: function() { - function isFloatArg(type) { - return String.fromCharCode(type).toLowerCase() in Runtime.set('f', 'e', 'g'); - } var cStyle = false; var textIndex = arguments[0]; var argIndex = 1; @@ -78,25 +75,26 @@ var Library = { } else { var _arguments = arguments; } - function getNextArg(type) { + function getNextArg(isFloat, size) { var ret; if (!cStyle) { ret = _arguments[argIndex]; argIndex++; } else { - if (isFloatArg(type)) { + if (isFloat) { ret = {{{ makeGetValue(0, 'argIndex', 'double') }}}; } else { ret = {{{ makeGetValue(0, 'argIndex', 'i32') }}}; } - argIndex += {{{ QUANTUM_SIZE === 1 ? 1 : "type === 'l'.charCodeAt(0) ? 8 : 4" }}}; + argIndex += {{{ QUANTUM_SIZE === 1 ? 1 : 'Math.max(4, size || 0)' }}}; } - return ret; + return +ret; // +: boolean=>int } var ret = []; var curr, next, currArg; while(1) { + var startTextIndex = textIndex; curr = {{{ makeGetValue(0, 'textIndex', 'i8') }}}; if (curr === 0) break; next = {{{ makeGetValue(0, 'textIndex+1', 'i8') }}}; @@ -134,7 +132,7 @@ var Library = { // Handle width. var width = 0; if (next == '*'.charCodeAt(0)) { - width = getNextArg('i'); + width = getNextArg(); textIndex++; next = {{{ makeGetValue(0, 'textIndex+1', 'i8') }}}; } else { @@ -153,7 +151,7 @@ var Library = { textIndex++; next = {{{ makeGetValue(0, 'textIndex+1', 'i8') }}}; if (next == '*'.charCodeAt(0)) { - precision = getNextArg('i'); + precision = getNextArg(); textIndex++; } else { while(1) { @@ -168,38 +166,94 @@ var Library = { var precision = 6; // Standard default. } - // Handle (ignore) integer sizes. - if (next == 'l'.charCodeAt(0) && {{{ makeGetValue(0, 'textIndex+2', 'i8') }}} == 'l'.charCodeAt(0) || - next == 'h'.charCodeAt(0) && {{{ makeGetValue(0, 'textIndex+2', 'i8') }}} == 'h'.charCodeAt(0)) { - textIndex += 2; - next = {{{ makeGetValue(0, 'textIndex+1', 'i8') }}}; - } else if (next == 'l'.charCodeAt(0) || next == 'L'.charCodeAt(0) || - next == 'h'.charCodeAt(0) || next == 'z'.charCodeAt(0) || - next == 'j'.charCodeAt(0) || next == 't'.charCodeAt(0)) { - textIndex++; - next = {{{ makeGetValue(0, 'textIndex+1', 'i8') }}}; + // Handle integer sizes. WARNING: These assume a 32-bit architecture! + var argSize; + switch (String.fromCharCode(next)) { + case 'h': + var nextNext = {{{ makeGetValue(0, 'textIndex+2', 'i8') }}}; + if (nextNext == 'h'.charCodeAt(0)) { + textIndex++; + argSize = 1; // char + } else { + argSize = 2; // short + } + break; + case 'l': + var nextNext = {{{ makeGetValue(0, 'textIndex+2', 'i8') }}}; + if (nextNext == 'l'.charCodeAt(0)) { + textIndex++; + argSize = 8; // long long + } else { + argSize = 4; // long + } + break; + case 'L': // long long + case 'q': // int64_t + case 'j': // intmax_t + argSize = 8; + break; + case 'z': // size_t + case 't': // ptrdiff_t + case 'I': // signed ptrdiff_t or unsigned size_t + argSize = 4; + break; + default: + argSize = undefined; } + if (argSize !== undefined) textIndex++; + next = {{{ makeGetValue(0, 'textIndex+1', 'i8') }}}; // Handle type specifier. if (['d', 'i', 'u', 'o', 'x', 'X', 'p'].indexOf(String.fromCharCode(next)) != -1) { // Integer. - var currArg = +getNextArg(next); // +: boolean=>int + var signed = next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0); + var currArg = getNextArg(false, argSize); + // Truncate to requested size. + argSize = argSize || 4; + var limit = undefined; + if (argSize == 4) { + limit = 0xFFFFFFFF; + } else if (argSize == 2) { + limit = 0xFFFF; + } else if (argSize == 1) { + limit = 0xFF; + } + if (limit !== undefined) { + currArg = currArg & limit; + if (!signed && currArg < 0 || signed && currArg > (limit - 1) / 2) { + currArg = ~(limit - currArg); + } + } + // Format the number. var currAbsArg = Math.abs(currArg); var argText; var prefix = ''; if (next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0)) { argText = currAbsArg.toString(10); } else if (next == 'u'.charCodeAt(0)) { - argText = unSign(currArg, 32).toString(10); + argText = unSign(currArg, 8 * argSize).toString(10); currArg = Math.abs(currArg); } else if (next == 'o'.charCodeAt(0)) { argText = (flagAlternative ? '0' : '') + currAbsArg.toString(8); - } else if (next == 'x'.charCodeAt(0)) { + } else if (next == 'x'.charCodeAt(0) || next == 'X'.charCodeAt(0)) { prefix = flagAlternative ? '0x' : ''; - argText = currAbsArg.toString(16); - } else if (next == 'X'.charCodeAt(0)) { - prefix = flagAlternative ? '0X' : ''; - argText = currAbsArg.toString(16).toUpperCase(); + if (currArg < 0) { + // Represent negative numbers in hex as 2's complement. + currArg = -currArg; + argText = (currAbsArg - 1).toString(16); + var buffer = []; + for (var i = 0; i < argText.length; i++) { + buffer.push((0xF - parseInt(argText[i], 16)).toString(16)); + } + argText = buffer.join(''); + while (argText.length < argSize * 2) argText = 'f' + argText; + } else { + argText = currAbsArg.toString(16); + } + if (next == 'X'.charCodeAt(0)) { + prefix = prefix.toUpperCase(); + argText = argText.toUpperCase(); + } } else if (next == 'p'.charCodeAt(0)) { prefix = '0x'; argText = currAbsArg.toString(16); @@ -230,20 +284,22 @@ var Library = { } } + // Insert the result into the buffer. argText = prefix + argText; argText.split('').forEach(function(chr) { ret.push(chr.charCodeAt(0)); }); - textIndex += 2; } else if (['f', 'F', 'e', 'E', 'g', 'G'].indexOf(String.fromCharCode(next)) != -1) { // Float. - var currArg = +getNextArg(next); // +: boolean=>int + var currArg = getNextArg(true, argSize); var argText; if (isNaN(currArg)) { argText = 'nan'; + flagZeroPad = false; } else if (!isFinite(currArg)) { argText = (currArg < 0 ? '-' : '') + 'inf'; + flagZeroPad = false; } else { var isGeneral = false; var effectivePrecision = Math.min(precision, 20); @@ -295,28 +351,31 @@ var Library = { if (flagAlwaysSigned && currArg >= 0) { argText = '+' + argText; } + } - // Add padding. - while (argText.length < width) { - if (flagLeftAlign) { - argText += ' '; + // Add padding. + while (argText.length < width) { + if (flagLeftAlign) { + argText += ' '; + } else { + if (flagZeroPad && (argText[0] == '-' || argText[0] == '+')) { + argText = argText[0] + '0' + argText.slice(1); } else { - if (flagZeroPad && (argText[0] == '-' || argText[0] == '+')) { - argText = argText[0] + '0' + argText.slice(1); - } else { - argText = (flagZeroPad ? '0' : ' ') + argText; - } + argText = (flagZeroPad ? '0' : ' ') + argText; } } } + + // Adjust case. if (next < 'a'.charCodeAt(0)) argText = argText.toUpperCase(); + + // Insert the result into the buffer. argText.split('').forEach(function(chr) { ret.push(chr.charCodeAt(0)); }); - textIndex += 2; } else if (next == 's'.charCodeAt(0)) { // String. - var copiedString = String_copy(getNextArg(next)); + var copiedString = String_copy(getNextArg()); if (precisionSet && copiedString.length > precision) { copiedString = copiedString.slice(0, precision); } @@ -331,23 +390,28 @@ var Library = { ret.push(' '.charCodeAt(0)); } } - textIndex += 2; } else if (next == 'c'.charCodeAt(0)) { - if (flagLeftAlign) ret = ret.concat(getNextArg(next)); + // Character. + if (flagLeftAlign) ret.push(getNextArg()); while (--width > 0) { ret.push(' '.charCodeAt(0)); } - if (!flagLeftAlign) ret = ret.concat(getNextArg(next)); - textIndex += 2; + if (!flagLeftAlign) ret.push(getNextArg()); } else if (next == 'n'.charCodeAt(0)) { - // TODO: Implement. Requires arguments to be passed in C-style. - // {{{ makeSetValue('argIndex', '0', 'ret.length', 'i32') }}} - textIndex += 2; + // Write the length written so far to the next parameter. + {{{ makeSetValue('getNextArg()', '0', 'ret.length', 'i32') }}} + } else if (next == '%'.charCodeAt(0)) { + // Literal percent sign. + ret.push(curr); } else { - // TODO: Add support for a/A specifiers (hex float). - ret.push(next); - textIndex += 2; // not sure what to do with this %, so print it + // Unknown specifiers remain untouched. + for (var i = startTextIndex; i < textIndex + 2; i++) { + ret.push({{{ makeGetValue(0, 'i', 'i8') }}}); + } } + textIndex += 2; + // TODO: Support a/A (hex float) and m (last error) specifiers. + // TODO: Support %1${specifier} for arg selection. } else { ret.push(curr); textIndex += 1; diff --git a/tests/printf/output.txt b/tests/printf/output.txt index bdf9d0bc..412c6b0f 100644 --- a/tests/printf/output.txt +++ b/tests/printf/output.txt @@ -1,3 +1,5 @@ +ab1.23cd +n=7 Characters: a A Decimals: 1977 650000 12 4 @@ -13,6 +15,15 @@ INF -INF nan NAN + nan +nan + nan +nan + inf +-inf +in%3.5valid +123 +456 0 0 0.0 @@ -8006,3 +8017,258 @@ NAN %-5p : 0x4f318 %-10p : 0x4f318 %-30p : 0x4f318 + +de +bcde +789abcde +789abcde + +de +bcde +789abcde +789abcde + +de +bcde +789abcde +789abcde +123456789abcde +123456789abcde + +789abcde +123456789abcde +789abcde +123456789abcde +789abcde + +-34 +-17186 +2023406814 +2023406814 + +-34 +-17186 +2023406814 +2023406814 + +-34 +-17186 +2023406814 +2023406814 +5124095576030430 +5124095576030430 + +2023406814 +5124095576030430 +2023406814 +5124095576030430 +2023406814 + +222 +48350 +2023406814 +2023406814 + +222 +48350 +2023406814 +2023406814 + +222 +48350 +2023406814 +2023406814 +5124095576030430 +5124095576030430 + +2023406814 +5124095576030430 +2023406814 +5124095576030430 +2023406814 + +22 +4322 +87654322 +87654322 + +22 +4322 +87654322 +87654322 + +22 +4322 +87654322 +87654322 +ffedcba987654322 +ffedcba987654322 + +87654322 +ffedcba987654322 +87654322 +ffedcba987654322 +87654322 + +34 +17186 +-2023406814 +-2023406814 + +34 +17186 +-2023406814 +-2023406814 + +34 +17186 +-2023406814 +-2023406814 +-5124095576030430 +-5124095576030430 + +-2023406814 +-5124095576030430 +-2023406814 +-5124095576030430 +-2023406814 + +34 +17186 +2271560482 +2271560482 + +34 +17186 +2271560482 +2271560482 + +34 +17186 +2271560482 +2271560482 +18441619978133520000 +18441619978133520000 + +2271560482 +18441619978133520000 +2271560482 +18441619978133520000 +2271560482 + +1234567.890123 +1234567.890123 +1234567.890123 +1234567.890123 + +-1234567.890123 +-1234567.890123 +-1234567.890123 +-1234567.890123 + +1234567.875000 +1234567.875000 +1234567.875000 +1234567.875000 + +-1234567.875000 +-1234567.875000 +-1234567.875000 +-1234567.875000 + +0 +0 +0 +0 +0 +0 +0 +0 + +1 +1 +1 +1 +1 +1 +1 +1 + +255 +65535 +4294967295 +18446744073709552000 +ff +ffff +ffffffff +ffffffffffffffff + +126 +32766 +2147483646 +140737488355326 +7e +7ffe +7ffffffe +7ffffffffffe + +127 +32767 +2147483647 +140737488355327 +7f +7fff +7fffffff +7fffffffffff + +128 +32768 +134217728 +549755813888 +80 +8000 +8000000 +8000000000 + +255 +65535 +4294967295 +281474976710655 +ff +ffff +ffffffff + +130 +32770 +2147483650 +18446603336221196000 +82 +8002 +80000002 +ffff800000000002 + +129 +32769 +2147483649 +18446603336221196000 +81 +8001 +80000001 +ffff800000000001 + +128 +32768 +4160749568 +18446743523953738000 +80 +8000 +f8000000 +ffffff8000000000 + +1 +1 +1 +18446462598732840000 +1 +1 +1 diff --git a/tests/printf/test.c b/tests/printf/test.c index ac662dca..d12e0d2e 100644 --- a/tests/printf/test.c +++ b/tests/printf/test.c @@ -2,6 +2,9 @@ #include <math.h> int main() { + int x; + printf("ab%gc%nd\n", 1.23f, &x); + printf("n=%d\n", x); printf("\n"); printf("Characters: %c %c\n", 'a', 65); printf("Decimals: %d %ld %lld %d\n", 1977, 650000L, 12LL, 4); @@ -17,6 +20,15 @@ int main() { printf("%lF\n", -INFINITY); printf("%lf\n", NAN); printf("%lF\n", NAN); + printf("%10f\n", NAN); + printf("%-10f\n", NAN); + printf("%010.2f\n", NAN); + printf("%-010.2f\n", NAN); + printf("%10.f\n", INFINITY); + printf("%-10.f\n", -INFINITY); + printf("in%3.5valid\n", 0); + printf("%qd\n", 123ll); + printf("%Id\n", 456); printf("%.f\n", 0.0f); printf("%.0f\n", 0.0f); printf("%.1f\n", 0.0f); @@ -8010,5 +8022,260 @@ int main() { printf("%-15s: %-5p\n", "%-5p", (void*)324376); printf("%-15s: %-10p\n", "%-10p", (void*)324376); printf("%-15s: %-30p\n", "%-30p", (void*)324376); + printf("\n"); + printf("%hhx\n", 0x789ABCDE); + printf("%hx\n", 0x789ABCDE); + printf("%x\n", 0x789ABCDE); + printf("%lx\n", 0x789ABCDE); + printf("\n"); + printf("%hhx\n", 0x789ABCDEl); + printf("%hx\n", 0x789ABCDEl); + printf("%x\n", 0x789ABCDEl); + printf("%lx\n", 0x789ABCDEl); + printf("\n"); + printf("%hhx\n", 0x0123456789ABCDEll); + printf("%hx\n", 0x0123456789ABCDEll); + printf("%x\n", 0x0123456789ABCDEll); + printf("%lx\n", 0x0123456789ABCDEll); + printf("%llx\n", 0x0123456789ABCDEll); + printf("%Lx\n", 0x0123456789ABCDEll); + printf("\n"); + printf("%zx\n", 0x0123456789ABCDEll); + printf("%jx\n", 0x0123456789ABCDEll); + printf("%tx\n", 0x0123456789ABCDEll); + printf("%qx\n", 0x0123456789ABCDEll); + printf("%Ix\n", 0x0123456789ABCDEll); + printf("\n"); + printf("%hhd\n", 0x789ABCDE); + printf("%hd\n", 0x789ABCDE); + printf("%d\n", 0x789ABCDE); + printf("%ld\n", 0x789ABCDE); + printf("\n"); + printf("%hhd\n", 0x789ABCDEl); + printf("%hd\n", 0x789ABCDEl); + printf("%d\n", 0x789ABCDEl); + printf("%ld\n", 0x789ABCDEl); + printf("\n"); + printf("%hhd\n", 0x0123456789ABCDEll); + printf("%hd\n", 0x0123456789ABCDEll); + printf("%d\n", 0x0123456789ABCDEll); + printf("%ld\n", 0x0123456789ABCDEll); + printf("%lld\n", 0x0123456789ABCDEll); + printf("%Ld\n", 0x0123456789ABCDEll); + printf("\n"); + printf("%zd\n", 0x0123456789ABCDEll); + printf("%jd\n", 0x0123456789ABCDEll); + printf("%td\n", 0x0123456789ABCDEll); + printf("%qd\n", 0x0123456789ABCDEll); + printf("%Id\n", 0x0123456789ABCDEll); + printf("\n"); + printf("%hhu\n", 0x789ABCDE); + printf("%hu\n", 0x789ABCDE); + printf("%u\n", 0x789ABCDE); + printf("%lu\n", 0x789ABCDE); + printf("\n"); + printf("%hhu\n", 0x789ABCDEl); + printf("%hu\n", 0x789ABCDEl); + printf("%u\n", 0x789ABCDEl); + printf("%lu\n", 0x789ABCDEl); + printf("\n"); + printf("%hhu\n", 0x0123456789ABCDEll); + printf("%hu\n", 0x0123456789ABCDEll); + printf("%u\n", 0x0123456789ABCDEll); + printf("%lu\n", 0x0123456789ABCDEll); + printf("%llu\n", 0x0123456789ABCDEll); + printf("%Lu\n", 0x0123456789ABCDEll); + printf("\n"); + printf("%zu\n", 0x0123456789ABCDEll); + printf("%ju\n", 0x0123456789ABCDEll); + printf("%tu\n", 0x0123456789ABCDEll); + printf("%qu\n", 0x0123456789ABCDEll); + printf("%Iu\n", 0x0123456789ABCDEll); + printf("\n"); + printf("%hhx\n", -0x789ABCDE); + printf("%hx\n", -0x789ABCDE); + printf("%x\n", -0x789ABCDE); + printf("%lx\n", -0x789ABCDE); + printf("\n"); + printf("%hhx\n", -0x789ABCDEl); + printf("%hx\n", -0x789ABCDEl); + printf("%x\n", -0x789ABCDEl); + printf("%lx\n", -0x789ABCDEl); + printf("\n"); + printf("%hhx\n", -0x0123456789ABCDEll); + printf("%hx\n", -0x0123456789ABCDEll); + printf("%x\n", -0x0123456789ABCDEll); + printf("%lx\n", -0x0123456789ABCDEll); + printf("%llx\n", -0x0123456789ABCDEll); + printf("%Lx\n", -0x0123456789ABCDEll); + printf("\n"); + printf("%zx\n", -0x0123456789ABCDEll); + printf("%jx\n", -0x0123456789ABCDEll); + printf("%tx\n", -0x0123456789ABCDEll); + printf("%qx\n", -0x0123456789ABCDEll); + printf("%Ix\n", -0x0123456789ABCDEll); + printf("\n"); + printf("%hhd\n", -0x789ABCDE); + printf("%hd\n", -0x789ABCDE); + printf("%d\n", -0x789ABCDE); + printf("%ld\n", -0x789ABCDE); + printf("\n"); + printf("%hhd\n", -0x789ABCDEl); + printf("%hd\n", -0x789ABCDEl); + printf("%d\n", -0x789ABCDEl); + printf("%ld\n", -0x789ABCDEl); + printf("\n"); + printf("%hhd\n", -0x0123456789ABCDEll); + printf("%hd\n", -0x0123456789ABCDEll); + printf("%d\n", -0x0123456789ABCDEll); + printf("%ld\n", -0x0123456789ABCDEll); + printf("%lld\n", -0x0123456789ABCDEll); + printf("%Ld\n", -0x0123456789ABCDEll); + printf("\n"); + printf("%zd\n", -0x0123456789ABCDEll); + printf("%jd\n", -0x0123456789ABCDEll); + printf("%td\n", -0x0123456789ABCDEll); + printf("%qd\n", -0x0123456789ABCDEll); + printf("%Id\n", -0x0123456789ABCDEll); + printf("\n"); + printf("%hhu\n", -0x789ABCDE); + printf("%hu\n", -0x789ABCDE); + printf("%u\n", -0x789ABCDE); + printf("%lu\n", -0x789ABCDE); + printf("\n"); + printf("%hhu\n", -0x789ABCDEl); + printf("%hu\n", -0x789ABCDEl); + printf("%u\n", -0x789ABCDEl); + printf("%lu\n", -0x789ABCDEl); + printf("\n"); + printf("%hhu\n", -0x0123456789ABCDEll); + printf("%hu\n", -0x0123456789ABCDEll); + printf("%u\n", -0x0123456789ABCDEll); + printf("%lu\n", -0x0123456789ABCDEll); + printf("%llu\n", -0x0123456789ABCDEll); + printf("%Lu\n", -0x0123456789ABCDEll); + printf("\n"); + printf("%zu\n", -0x0123456789ABCDEll); + printf("%ju\n", -0x0123456789ABCDEll); + printf("%tu\n", -0x0123456789ABCDEll); + printf("%qu\n", -0x0123456789ABCDEll); + printf("%Iu\n", -0x0123456789ABCDEll); + printf("\n"); + printf("%hhf\n", 1234567.890123456789); + printf("%hf\n", 1234567.890123456789); + printf("%f\n", 1234567.890123456789); + printf("%lf\n", 1234567.890123456789); + printf("\n"); + printf("%hhf\n", -1234567.890123456789); + printf("%hf\n", -1234567.890123456789); + printf("%f\n", -1234567.890123456789); + printf("%lf\n", -1234567.890123456789); + printf("\n"); + printf("%hhf\n", 1234567.890123456789f); + printf("%hf\n", 1234567.890123456789f); + printf("%f\n", 1234567.890123456789f); + printf("%lf\n", 1234567.890123456789f); + printf("\n"); + printf("%hhf\n", -1234567.890123456789f); + printf("%hf\n", -1234567.890123456789f); + printf("%f\n", -1234567.890123456789f); + printf("%lf\n", -1234567.890123456789f); + printf("\n"); + printf("%hhu\n", 0); + printf("%hu\n", 0); + printf("%u\n", 0); + printf("%llu\n", 0ll); + printf("%hhx\n", 0); + printf("%hx\n", 0); + printf("%x\n", 0); + printf("%llx\n", 0ll); + printf("\n"); + printf("%hhu\n", 1); + printf("%hu\n", 1); + printf("%u\n", 1); + printf("%llu\n", 1ll); + printf("%hhx\n", 1); + printf("%hx\n", 1); + printf("%x\n", 1); + printf("%llx\n", 1ll); + printf("\n"); + printf("%hhu\n", -1); + printf("%hu\n", -1); + printf("%u\n", -1); + printf("%llu\n", -1ll); + printf("%hhx\n", -1); + printf("%hx\n", -1); + printf("%x\n", -1); + printf("%llx\n", -1ll); + printf("\n"); + printf("%hhu\n", 0x7E); + printf("%hu\n", 0x7FFE); + printf("%u\n", 0x7FFFFFFE); + printf("%llu\n", 0x7FFFFFFFFFFEll); + printf("%hhx\n", 0x7E); + printf("%hx\n", 0x7FFE); + printf("%x\n", 0x7FFFFFFE); + printf("%llx\n", 0x7FFFFFFFFFFEll); + printf("\n"); + printf("%hhu\n", 0x7F); + printf("%hu\n", 0x7FFF); + printf("%u\n", 0x7FFFFFFF); + printf("%llu\n", 0x7FFFFFFFFFFFll); + printf("%hhx\n", 0x7F); + printf("%hx\n", 0x7FFF); + printf("%x\n", 0x7FFFFFFF); + printf("%llx\n", 0x7FFFFFFFFFFFll); + printf("\n"); + printf("%hhu\n", 0x80); + printf("%hu\n", 0x8000); + printf("%u\n", 0x8000000); + printf("%llu\n", 0x8000000000ll); + printf("%hhx\n", 0x80); + printf("%hx\n", 0x8000); + printf("%x\n", 0x8000000); + printf("%llx\n", 0x8000000000ll); + printf("\n"); + printf("%hhu\n", 0xFF); + printf("%hu\n", 0xFFFF); + printf("%u\n", 0xFFFFFFFF); + printf("%llu\n", 0xFFFFFFFFFFFFll); + printf("%hhx\n", 0xFF); + printf("%hx\n", 0xFFFF); + printf("%x\n", 0xFFFFFFFF); + printf("\n"); + printf("%hhu\n", -0x7E); + printf("%hu\n", -0x7FFE); + printf("%u\n", -0x7FFFFFFE); + printf("%llu\n", -0x7FFFFFFFFFFEll); + printf("%hhx\n", -0x7E); + printf("%hx\n", -0x7FFE); + printf("%x\n", -0x7FFFFFFE); + printf("%llx\n", -0x7FFFFFFFFFFEll); + printf("\n"); + printf("%hhu\n", -0x7F); + printf("%hu\n", -0x7FFF); + printf("%u\n", -0x7FFFFFFF); + printf("%llu\n", -0x7FFFFFFFFFFFll); + printf("%hhx\n", -0x7F); + printf("%hx\n", -0x7FFF); + printf("%x\n", -0x7FFFFFFF); + printf("%llx\n", -0x7FFFFFFFFFFFll); + printf("\n"); + printf("%hhu\n", -0x80); + printf("%hu\n", -0x8000); + printf("%u\n", -0x8000000); + printf("%llu\n", -0x8000000000ll); + printf("%hhx\n", -0x80); + printf("%hx\n", -0x8000); + printf("%x\n", -0x8000000); + printf("%llx\n", -0x8000000000ll); + printf("\n"); + printf("%hhu\n", -0xFF); + printf("%hu\n", -0xFFFF); + printf("%u\n", -0xFFFFFFFF); + printf("%llu\n", -0xFFFFFFFFFFFFll); + printf("%hhx\n", -0xFF); + printf("%hx\n", -0xFFFF); + printf("%x\n", -0xFFFFFFFF); return 0; } |