Thread: Is there a standard function?

  1. #181
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by iMalc View Post
    Okay final version. Pulled out all the stops now... Only two divs or mods in the whole thing. I even got rid of two gotos! Time to retire this one:
    Code:
    int iMalcsUltimateFormat(long snum, char s[])
    {
        char *ps = s;
        unsigned long num1 = snum, num2, num3, div;
        if (snum < 0) {
            *ps++ = '-';
            num1 = -snum;
        }
        if (num1 < 10000) {
            if (num1 < 10) goto L1;
            if (num1 < 100) goto L2;
            if (num1 < 1000) goto L3;
        } else {
            num2 = num1 / 10000;
            num1 -= num2 * 10000;
            if (num2 < 10000) {
                if (num2 < 10) goto L5;
                if (num2 < 100) goto L6;
                if (num2 < 1000) goto L7;
            } else {
                num3 = num2 / 10000;
                num2 -= num3 * 10000;
                if (num3 >= 10) {
                    *ps++ = '0' + (char)(div = (num3*6554UL)>>16); num3 -= div*10;
                    *ps++ = ',';
                }
                *ps++ = '0' + (char)(num3);
            }
            *ps++ = '0' + (char)(div = (num2*8389UL)>>23); num2 -= div*1000;
    L7:
            *ps++ = '0' + (char)(div = (num2*5243UL)>>19); num2 -= div*100;
            *ps++ = ',';
    L6:
            *ps++ = '0' + (char)(div = (num2*6554UL)>>16); num2 -= div*10;
    L5:
            *ps++ = '0' + (char)(num2);
        }
        *ps++ = '0' + (char)(div = (num1*8389UL)>>23); num1 -= div*1000;
        *ps++ = ',';
    L3:
        *ps++ = '0' + (char)(div = (num1*5243UL)>>19); num1 -= div*100;
    L2:
        *ps++ = '0' + (char)(div = (num1*6554UL)>>16); num1 -= div*10;
    L1:
        *ps++ = '0' + (char)(num1);
        *ps = '\0';
        return ps - s;
    }
    Very good, dude. :-)

    this evening, back home, I'll give a better look at that.

    I'm actually unable to stay longer.

    Bye for now.

  2. #182
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    >_<

    So I'm the only one using `log2', `sin', polar coordinates, and a massive array to do this?

    FINE!

    *thplblblbltlttlbltl*

    Soma > off to pout

  3. #183
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by phantomotap View Post
    >_<

    So I'm the only one using `log2', `sin', polar coordinates, and a massive array to do this?

    FINE!

    *thplblblbltlttlbltl*

    Soma > off to pout
    What are you talking about phantomotap?
    :-)

  4. #184
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    @Elysia:

    You had to add an underline in front of a function name -- GET OVER IT ALREADY, and quit yer damn whining.

    Quote Originally Posted by phantomotap View Post
    >_<

    So I'm the only one using `log2', `sin', polar coordinates, and a massive array to do this?

    FINE!

    *thplblblbltlttlbltl*

    Soma > off to pout
    Did Frkton time your program on his system, Soma?

  5. #185
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    @Elysia:

    You had to add an underline in front of a function name -- GET OVER IT ALREADY, and quit yer damn whining.
    But you didn't, and therefore it complained about it being a POSIX function. All I did was point that out.
    Can we agree to stop this now? If you say yes, I'll say yes.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #186
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by Elysia View Post
    But you didn't, and therefore it complained about it being a POSIX function. All I did was point that out.
    Can we agree to stop this now? If you say yes, I'll say yes.
    Y E S ! ! ! By all means. Game over. Let's play something else. :-)

    The coauthor of my version pointed to the problem of not correctly handling
    string termination, so He [clive] suggested to add this line of code:
    Code:
      x = len_str;
    
      buffer[x--] = 0;
    and now the 'L' terminated string problem is over. The timings are actually:
    Code:
                Testing version : 0.60
    
               --------------------------
    
     The value of num is: -1234567890
    
     The formatted value of num is: -1.234.567.890
     Elapsed ClickTime: 1.177
     to perform 10.000.000 cycles of the formatting function
    About 1.2 seconds.

    In the next days I'll try the code some of you have posted, but I've to
    adapt it to the testpad, so it'll take a while. :-(

    I've also to add a function to generate random numbers, and
    the display of the results for the various versions. No time at the moment.

    And in 5 minutes I tryed iMalc smart solution:

    Code:
                Testing version : 0.60
    
                --------------------------
    
     The value of num is: -1234567890
    
     The formatted value of num is: -1,234,567,890
    
     Elapsed ClickTime: 463
     to perform 10,000,000 cycles of the formatting function
    That looks like the potential winner so far :-)
    Last edited by frktons; 07-07-2010 at 10:02 AM.

  7. #187
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    But you didn't, and therefore it complained about it being a POSIX function. All I did was point that out.
    Can we agree to stop this now? If you say yes, I'll say yes.
    @Elysia:
    I didn't add the underline, because my compilers either don't allow and/or require it. That was the only ultoa() function that was portable between my two compilers.

    You did not just "point it out", you launched into your same old tirade about my compilers, and I'm tired of you whining about them. I've spent several hundred dollars on these compilers, and I have some large programs that don't work on any other compilers. I need to use these two compilers. You can .......... and moan about it as long as you like.

  8. #188
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by Adak View Post
    Code:
    But you didn't, and therefore it complained about it being a POSIX function. All I did was point that out.
    Can we agree to stop this now? If you say yes, I'll say yes.
    @Elysia:
    I didn't add the underline, because my compilers either don't allow and/or require it. That was the only ultoa() function that was portable between my two compilers.

    You did not just "point it out", you launched into your same old tirade about my compilers, and I'm tired of you whining about them. I've spent several hundred dollars on these compilers, and I have some large programs that don't work on any other compilers. I need to use these two compilers. You can .......... and moan about it as long as you like.
    Ah! Ah! Ah! Ah! Ah! :-)
    From my point of view you can use whatever you like, whenever you
    think it is fitted for your pourposes, and to whatever extend you can imagine.
    :-)

    By the way, did you come with any turbo C/MSVSC/WTK idea about the
    main task of this thread?
    Let me know and enjoy.

  9. #189
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    One program from each one, actually. I'm looking forward to seeing how Whiteflag's, Soma's, and iMalc's programs do in your testing.
    Last edited by Adak; 07-07-2010 at 04:51 PM.

  10. #190
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    @cyberfish:

    if you can help me solve these compiling errors of your code
    I can try it on my testpad:
    Code:
     error #2048: Undeclared identifier 'BUF_LEN'.
     Missing prototype for 'memmove'.
    *** Error code: 1 ***
    Done.

  11. #191
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by Adak View Post
    One program from each one, actually. I'm looking forward to seeing how Whitehorse's, Soma's, and iMalc's programs do in your testing.
    I tried iMalc's code, and it looks quite efficient as I already posted. :-)
    Don't know where are soma's and Whitehorse's so far, let me look for them.

  12. #192
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by kermit View Post
    Code:
    stop = clock();
    
        sign = false;
        int_format((int)(stop-start));
        printf("\n Elapsed ClickTime: %s",buffer);
        for (x=0; x < 15; x++)
            buffer[x] = ' \0';
    Perhaps that is giving you some trouble?
    Yes indeed. I managed to change that. Thanks.

  13. #193
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by whiteflags View Post
    No this is basically a dick waving contest. Although AFAIK the only thing printf is guaranteed to do in response to locale changes is change the decimal point. Still important.

    Anyway thank you for the contribution iMalc! This made for a fun profile. When I discovered my IDE had a profiler.

    Anyway, in the interest of full disclosure, I unwound the recursion in my method and used another stack instead. It could probably be smaller. I did also profile my recursive version, but did not include it in this test.

    I had to make significant changes to Adak's code to get it to compile. It probably isn't fair, but I had to do things like delete C++ comments and make sure his function actually printed output like the rest can.

    In an upset, Adak's method is the slowest, with me trailing iMalc by a hair. If frktons wants to read the profile properly, I suggest this page. Profile output is not execution time -- it's something better. The actual execution time was something not pretty, like 800-900 seconds.

    Because it may be pertinent, this is a debug build with no optimization from mingw (gcc 3.4.5), on a P4 2.6GHz architecture. I hope this is fair to everyone. I did my utmost.
    Hi whiteflags.

    I tried your code, but it displays million lines on the screen,
    so it is not something I can test for performance. :-(

    What should this test program shows? Remember I'm a beginner
    and many things are obviously unknown to me.

    I can analyse your code with my eyes, not with a profiler for the time
    being, and get some insight/inspiration from it. But if you think it is
    worth to try for performance, please post a suitable version.

    Thanks

  14. #194
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    I'm sorry for the confusion. I did not post any source.

    I only posted that comment to playfully mock the other posters.

    *shrug*

    Anyway. What can you really expect from a 1800 MiB array loosely indexed by repeatedly dividing `double' values?

    Soma

  15. #195
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    @Elysia:
    I didn't add the underline, because my compilers either don't allow and/or require it. That was the only ultoa() function that was portable between my two compilers.

    You did not just "point it out", you launched into your same old tirade about my compilers, and I'm tired of you whining about them. I've spent several hundred dollars on these compilers, and I have some large programs that don't work on any other compilers. I need to use these two compilers. You can .......... and moan about it as long as you like.
    And I am getting tired about your using of old non-standard compliant compilers which is completely against the spirit of the boards. You are using the very same compiler/IDE that we urge newbies on the board to avoid. You're not helping when you post code compiled in that because it creates the exact kind of code that we do not want newbies to use/see/become familiar with.

    You are free to use these compilers as you need for your large projects, but why can you not simply use a modern standard compiler when creating new projects and sharing newly written code with newbies? Is it too much to ask?
    There are free alternatives out there! You don't have to spend a dime on that.

    @frktons:
    Instead of quadraple posting, please use the edit button. You can quote multiple posts at once. There is a button for that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  3. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM