Hi Adam. Dne 8. dubna 2012 15:47 Adam Saleh <[email protected]> napsal(a): >> Hi Adam, >> thanks for the patch. >> >> I have a few comments. >> >> Please, use the same C style as we do. In general, we are more >> generous with spaces than you were in your patch. We do put them >> around operators or after keywords (such as if or while). > > Ok, looked into the style guide, hope I fixed few things :) Unfortunately, not all of them. There are still some differences in your patch to our coding style. As I already mentioned, we do put spaces after if [e.g. if (cond) {, not if(cond){].
>> And it seems to me that there is one bug in your implementation. >> Specifier %5.0f shall print the number without the fractional part. >> But your implementation prints at least one digit. > > Fixed, added a test. For me it does not work. The print2 test does not print two identical lines. Not talking about the fact that the printed format (first line) does not match the actual output. And AFAIK when the precision is not specified, it defaults to 6. At least as described in [1] and I can see no reason why we shall not follow it in this case. And I encountered another problem. I tried to build your new patch for ia32 profile and I ended with following error: uspace/lib/c/generic/io/printf_core.c:559: undefined reference to `__fixunsdfdi' This function is needed for 32bit architectures and it converts float to long long. - Vojta [1] http://pubs.opengroup.org/onlinepubs/007908799/xsh/fprintf.html > >> Unless you want to provide your own fix, I will probably fix these >> some time next week because this is something I would like to have >> merged into mainline. >> >> Thanks. >> >> - Vojta >> >> Dne 7. dubna 2012 16:05 Adam Saleh <[email protected]> napsal(a): >>> Sending my patch. Hopefully fixes trac.helenos.org/ticket/221 >>> >>> Adam >>> >>> _______________________________________________ >>> HelenOS-devel mailing list >>> [email protected] >>> http://lists.modry.cz/cgi-bin/listinfo/helenos-devel >>> >> >> _______________________________________________ >> HelenOS-devel mailing list >> [email protected] >> http://lists.modry.cz/cgi-bin/listinfo/helenos-devel > > _______________________________________________ > HelenOS-devel mailing list > [email protected] > http://lists.modry.cz/cgi-bin/listinfo/helenos-devel >
# Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: [email protected] # target_branch: bzr://bzr.helenos.org/mainline/ # testament_sha1: 0cfa6f7738543d146058b7811a1f3c0335c3b6e8 # timestamp: 2012-04-08 16:42:18 +0200 # base_revision_id: jiri@wiwaxia-20120405224251-l7sx79xi2488v3ko # # Begin patch === modified file 'uspace/app/tester/print/print2.c' --- uspace/app/tester/print/print2.c 2011-08-23 17:44:33 +0000 +++ uspace/app/tester/print/print2.c 2012-04-08 14:39:47 +0000 @@ -51,6 +51,10 @@ TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); TPRINTF("Real output: [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21); + + TPRINTF("Testing printf(\"%%0.0f\ %%f %%0.2f\", 3.1415,3.1415,-3.1415,123.4567):\n"); + TPRINTF("Expected output: [3] [3.1] [3.14] [-3.141] [00123.45670] \n"); + TPRINTF("Real output: [%0.0f] [%f] [%0.2f] [%0.3f] [%5.5f] \n\n", 3.1415, 3.1415,3.1415,-3.1415,123.4567); return NULL; } === modified file 'uspace/lib/c/generic/io/printf_core.c' --- uspace/lib/c/generic/io/printf_core.c 2011-08-23 17:44:33 +0000 +++ uspace/lib/c/generic/io/printf_core.c 2012-04-08 14:39:47 +0000 @@ -98,6 +98,7 @@ PrintfQualifierByte = 0, PrintfQualifierShort, PrintfQualifierInt, + PrintfQualifierFloat, PrintfQualifierLong, PrintfQualifierLongLong, PrintfQualifierPointer, @@ -360,7 +361,7 @@ return ((int) counter); } -/** Print a number in a given base. +/** Print an integer in a given base. * * Print significant digits of a number in given base. * @@ -526,6 +527,78 @@ return ((int) counter); } + +/** Print a float in base 10. + * + * Print significant digits of a number in given base. + * + * @param num Number to print. + * @param width Width modifier. + * @param precision Precision modifier. + * @param flags Flags that modify the way the number is printed. + * + * @return Number of characters printed. + * + */ +static int print_float(double num, int width, int precision, + uint32_t flags, printf_spec_t *ps) +{ + int base; + base = 10; + int counter; counter=0; + int result; + + /*handle negative numbers*/ + uint32_t flags_fraction=flags; + if(num < 0){ + (flags) |= __PRINTF_FLAG_NEGATIVE; + num *= -1; + } + + /*get the whole part*/ + uint64_t whole = num; + + /*print the whole part*/ + result = print_number(whole,0,width,base,flags,ps); + if(result < 0){ + return result; + } + counter += result; + + /*If i don't want to printout the fractional part, I can end*/ + if(precision == 0){ + return ((int) counter); + } + + /*print the dot*/ + result = print_char('.',1,flags,ps); + if(result < 0){ + return result; + } + counter++; + + /*get fraction*/ + uint64_t fraction; + { + num -= whole; + while(precision>1){ + num *= 10; + precision--; + } + num *= 10; + fraction = num; + } + + /*print the rest (witout negative flag)*/ + result = print_number(fraction,0,0,base,flags_fraction,ps); + if(result < 0){ + return result; + } + counter += result; + + return ((int) counter); +} + /** Print formatted string. * * Print string formatted according to the fmt parameter and variadic arguments. @@ -601,7 +674,9 @@ * * - d, i Print signed decimal number. There is no difference between d * and i conversion. - * + * + * - f Print signed decimal float. + * * - u Print unsigned decimal number. * * - X, x Print hexadecimal number with upper- or lower-case. Prefix is @@ -756,6 +831,10 @@ qualifier = PrintfQualifierLongLong; } break; + case 'f': + /* Float */ + qualifier = PrintfQualifierFloat; + break; case 'z': qualifier = PrintfQualifierSize; i = nxt; @@ -821,6 +900,9 @@ break; case 'd': case 'i': + /* necessary to case 'f' again, so it won't fall through + * and have signed printing in sub routines */ + case 'f': flags |= __PRINTF_FLAG_SIGNED; case 'u': break; @@ -880,14 +962,28 @@ size = sizeof(size_t); number = (uint64_t) va_arg(ap, size_t); break; + /*Float is a known qualifier, but will be a special case*/ + case PrintfQualifierFloat: + break; default: /* Unknown qualifier */ counter = -counter; goto out; } - if ((retval = print_number(number, width, precision, - base, flags, ps)) < 0) { + /*Either float or integer*/ + if(PrintfQualifierFloat == qualifier) { + double fnumber; + size = sizeof(float); + fnumber = (float) va_arg(ap, double); + retval = print_float(fnumber, width, precision, + flags, ps); + }else{ + retval = print_number(number, width, precision, + base, flags, ps); + } + + if (retval < 0) { counter = -counter; goto out; } # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZT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Cf9D w62Q6iMzYITgcUlxDdFSsWPUdoH/HekiYxcHLudJFki5Pigol8M0XkRetp0srKiJD2BjT0RytcbU /wC3lfkjuHBgGCQqBI/eOQSRsOwCcHLS47DpmHY/xIMvyH9BxEpCZFaiJWVLKHpheE7wecJ6bTng a01LDAhTfpAigdHqOkxmfdkREq5rRDnmMKCgcWQ+Boe8mKt/gth6YhiADAwiSNQNJROy2pS0HGHT MHGFxYN2xjY4yUHSnRCdU61QigMvRj2szLEMEYCDSAQtPFhM+ZF7ggxsSqYQGjCDT8pq1XuoB4Sx PvtMG2Z22SiEdXnN5bKEBjUonaAO1WBPMGtQmIAvEC5MewgBBhNoOQ2eDIKkUBqlBI8UkZOXGTVy L9QcyuiTMEDFgoIIitaYReEaQAgSgmWAV1fwRaaltQT7i3h6EVEgoGANeIcWwXQBmcJF2QOj6gf7 KdFob2MBctwjrQu5CrOOfDZUOB5KQ6Rr0y6u2YftOSdhkQ3ld1Mk6xPPCdBmxkxAqYGh902JOLZK kKp/4u5IpwoSAhXpLIA=
_______________________________________________ HelenOS-devel mailing list [email protected] http://lists.modry.cz/cgi-bin/listinfo/helenos-devel
