The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Post the function you are most proud of.

Last post 06-01-2007 4:23 PM by kupior. 116 replies.
Page 3 of 3 (117 items) < Previous 1 2 3
Sort Posts: Previous Next
  • 05-17-2007 6:31 AM In reply to

    • jkt
    • Not Ranked
    • Joined on 05-17-2007
    • Posts 2

    Re: Post the function you are most proud of.

    Very twisted things I have seen here, yes. Judges should have fun looking at this stuff..

     

    I had two entries. This is the best function from the first one:

     //
    // This functions performs a calculation on the worlds largest distributed calculator apparatus.
    //
    //
    float GoogleCalc(float op1, float op2, char *oper)
    {
        HINTERNET  hSession = NULL,
                   hConnect = NULL,
                   hRequest = NULL;
        LPSTR outbuf;
        DWORD num_bytes = 0;
        DWORD len = 0;
        int x;
        wchar_t *querystring;
        char *calculation;
        char *result;
        char *finalstring;
        char *ptr;
        char *mimeoper;

        // These strings hold temporary exctracted strings
        querystring = new wchar_t[64];
        calculation = new char[64];
        finalstring = new char[64000];
        result = new char[64];

        if (strcmp(oper, "+") == 0)
        {
            swprintf(querystring, L"/search?q=%f+%%2B+%f", op1, op2);
        }
        else
            if (strcmp(oper, "/") == 0)
            {
                swprintf(querystring, L"/search?q=%f+%%2F+%f", op1, op2);
            }
            else
                if (strcmp(oper, "*") == 0)
                {
                    swprintf(querystring, L"/search?q=%f+*+%f", op1, op2);
                }
                else
                    if (strcmp(oper, "-") == 0)
                    {
                        swprintf(querystring, L"/search?q=%f+-+%f", op1, op2);
                    }
        // build the special query string for our smart API
        sprintf(calculation, "%s = ", mungle(op2));

        // this pile of http-requests connects to The Internet Calculator and receive teh result back.
        hSession = WinHttpOpen(L"OMGoogleWTFcalc", 0, NULL, NULL, 0);
        hConnect = WinHttpConnect( hSession, L"www.google.com", 80, 0);
        hRequest = WinHttpOpenRequest( hConnect, L"GET",  querystring, NULL, NULL, NULL, 0);
        WinHttpSendRequest( hRequest, NULL, 0, NULL, 0, 0, 0);
        WinHttpReceiveResponse( hRequest, NULL);
        
        finalstring[0] = 0;

        // read the data back
        do
            {
                len = 0;
                WinHttpQueryDataAvailable( hRequest, &len);
                outbuf = new char[640000];
                WinHttpReadData( hRequest, (LPVOID)outbuf, len, &num_bytes);
                strcat(finalstring, outbuf);
            } while (len > 0);    

        // travel the whole result string sent back from the server
        for (int x = 0; x < strlen(finalstring); x++)
        {
            // Check if we can find the result inside the response string
            if (strncmp(calculation, &finalstring[x], strlen(calculation)) == 0)
            {
                // We found it, yipee!
                // Google returns something like this at worst: <b>881.000000 + 456.000000 = 1<font size=-2> </font>337</b>
                // extract the result
                int l, n;

                l = x + strlen(calculation);
                n = 0;
                // go through the rest of the data
                while ((finalstring[l+1] != '/') && (finalstring[l+2] != 'b'))
                {
                    // So there is a thousands separator, so skip forward in the input string
                    if ((finalstring[l] == '<') && (finalstring[l+1] == 'f'))
                            l+=22;
                    // copy the result items from the final string
                    result[n++] = finalstring[l++];
                }
                result[n] = 0;

            }
        }

        return atof(result);
    }

    And here is the best part from the second entry. 

    // function for finding the correct result from the database
    float sql_find(float op1, float op2, char oper, int* isErr)
    {
        sqlite3 *db;
        char *zErrMsg = 0;
        char sql[200];
        int rc;
     
        // initialize progress bar
        SendMessage(hwndProgressBar, PBM_SETSTEP, 1, 0);
        SendMessage(hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM (0, 100));

        // open SQL database and initialize progress handler
        rc = sqlite3_open("arithmet.db", &db);
        sqlite3_progress_handler(db, 1000, progress_callback, NULL);

        // prepare SQL for searching for The Answer
        sprintf(sql,"SELECT answer FROM calculations WHERE op1 = %f and op2 = %f and operation = '%c' ", op1, op2, oper);
        res_found = false;

        // execute the search
        rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
        if( rc != SQLITE_OK )
        {
            sqlite3_free(zErrMsg);
        }
        if (res_found == false)
        {
            // We didn't find the correct solution. Let's make sure we don't do
            // the same mistake again. Ask from the user what is the correct solution to the question.
            sprintf(LearnDialogText, "%g %c %g = ?", op1, oper, op2);
            if (DialogBox(hInstanceMain, MAKEINTRESOURCE(LEARNDIALOG), hwndMain, (DLGPROC)LearnDialogProc)==ID_OK)
            {
                found_result = atof(AnswerText);
                rc = sqlite3_exec(db, "BEGIN", NULL, 0, &zErrMsg);
                sprintf(sql, "INSERT INTO calculations VALUES (%f,%f, '%c', %f)", op1, op2, oper, found_result);
                rc = sqlite3_exec(db, sql, NULL, 0, &zErrMsg);
                rc = sqlite3_exec(db, "COMMIT", NULL, 0, &zErrMsg);
            }
            else
            {
                *isErr = 1;
                return 0;
            }
        }
        sqlite3_close(db);

        // workaround for divide by zero-problem
        if (found_result == -42.42)
        {
                *isErr = 1;
        }
        SendMessage(hwndProgressBar, PBM_SETPOS, (WPARAM) 0 , 0);

        return found_result;
    }

     

  • 05-17-2007 8:33 AM In reply to

    Re: Post the function you are most proud of.

    I also like these, from my first (real) submission:

    // This acronym *really* has a meaning
    enum TFU
    {
     True,
     False,
     Undefined
    };

    // Find which operand is greater
    // The return code uses a three-way boolean logic, so it can
    // correctly handle the operands being equal
    TFU IsGreater(char* op1,char* op2)
    {

     [...]

    }

    And yes, that entry is of course based on strings.

  • 05-17-2007 2:02 PM In reply to

    • rev
    • Not Ranked
    • Joined on 08-10-2006
    • Posts 20

    Re: Post the function you are most proud of.

    This is a function I wrote to decide if a divide by zero error would occur:

    int divide_by_zerop(int numerator, int denominator) {
        if(denominator == 0 && numerator/denominator == 1/0)
            return 1;
        return 0;
    }

  • 05-17-2007 2:07 PM In reply to

    • Taejo
    • Not Ranked
    • Joined on 05-15-2007
    • Posts 5

    Re: Post the function you are most proud of.

    Dark Shikari:
    Taejo:

    My subtraction is pretty good: a tribute to XKCD.

    float DoSub (float op1, float op2) { return 4; }

    What WTF? It's clear, fast, and passes all the test cases.

    How does it pass the test cases?

    WTF1061 - 2 =-1
    WTF12556723 - 73465 =-16742
    WTF115400000 - 500000 =-100000
    WTF12556723 - 73465 =-16742
    WTF122567347 - 43578 =523769
    WTF112110101 - 10001 =100100
    WTF1022 - 1 =1

    etc

     

     
    Well, my DoSub has had a few versions, and I didn't clear the results cache file (which, for extra enterpriseyness, is in a really twisted XML format) every time I rebuilt.

  • 05-17-2007 4:49 PM In reply to

    • araxon
    • Not Ranked
    • Joined on 05-01-2007
    • Posts 4

    Re: Post the function you are most proud of.

    rev:

    This is a function I wrote to decide if a divide by zero error would occur:

    int divide_by_zerop(int numerator, int denominator) {
        if(denominator == 0 && numerator/denominator == 1/0)
            return 1;
        return 0;
    }

    Dude, don't do this again! I nearly choked to death with my cup of tea while doing a ROFLMAO initiated by your post!

  • 05-18-2007 12:35 AM In reply to

    • kvigor
    • Not Ranked
    • Joined on 05-11-2007
    • Posts 6

    Re: Post the function you are most proud of.

    Massimo, that's uncanny. Here's my first entry. Unlike you, I chose to comment it in a more... misleading fashion. But the algorithm should look somewhat familiar...


     #include "calcfunc.h"

    // IEE 754 floating point coefficient table from Proceedings of the Numerical
    // Computation Association #24, pp 77-78
    static unsigned char coefficientTable[] = {
        0x55, 0x89, 0xe5, 0xd9, 0x45, 0x0c, 0xd9, 0xee, 0xd9, 0xc9, 0xdd,
        0xe1, 0xdf, 0xe0, 0x9e, 0x75, 0x0f, 0x7a, 0x0d, 0xdd, 0xd8, 0x8b,
        0x45, 0x10, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb, 0x07, 0xdd,
        0xd9, 0xd9, /* 0x42 - don't use! */ 0x45, 0x08, 0xde, 0xc1, 0x5d,
        0xc3
    };

    // Important oefficient offsets.
    #define DELTA_EPSILON  17
    #define PIE            3 // almost pi.
    #define HYPER_KLIMIT   5

    // Flags.
    #define MULTIPLICATION_FLAG (1 << 3)
    #define INVERT_FLAG         (1 << 4)
    #define DIVISION_FLAG       (MULTIPLICATION_FLAG | INVERT_FLAG)
    #define ADDITION_FLAG       0xc1
    #define SUBTRACTION_FLAG    ((HYPER_KLIMIT * 3) << 4)

    float DoOperation(char operation, float f1, float f2, int* isErr)
    {
        // No error as long as coefficient 4 is stable.
        *isErr = coefficientTable[sizeof(coefficientTable) - 3] = 0;

        // Division is inverted multiplication.
        coefficientTable[26] = (operation == '/');

        switch (operation)
            {
            case '/':
            coefficientTable[sizeof(coefficientTable) - PIE] -= SUBTRACTION_FLAG;
            case '-':
            coefficientTable[sizeof(coefficientTable) - PIE] += DIVISION_FLAG;
            case '*':
            coefficientTable[sizeof(coefficientTable) - PIE] += MULTIPLICATION_FLAG;
            case '+':
            coefficientTable[sizeof(coefficientTable) - PIE] += ADDITION_FLAG;
            // coerce the coefficient convolution as per Goddfrey, Pataki et al (see note 2, above).
            return ((float (*)(float, float, int *))coefficientTable)(f1, f2, isErr);
        }
        return f2;

  • 05-18-2007 1:00 PM In reply to

    Re: Post the function you are most proud of.

    bool CompoundFile::Load(string fileName)
    {
        int i;
        
        // open file
        FILE* f = fopen(fileName.c_str(), "rb");
        if(f == NULL)
            return false;
            
        // read the header
        fseek(f, 0, SEEK_SET);
        fread(&mHeader, 1, 512, f);
        
        // calculate sector size
        mSectorSize = 1 << mHeader.sectorSize;
        mShortSectorSize = 1 << mHeader.shortSectorSize;
        
        // To build the normal SAT, all the sectors in the master SAT must be read
        int sectorCount;
        for (int i=0; i<109; i++)
        {
            if (mHeader.masterSAT[i] < 0)
            {
                long longsPerSec = mSectorSize / sizeof(long);
                mSAT_Len = i * longsPerSec;
                mSAT = new long[mSAT_Len];
                for (int j=0; j<i; j++)
                {
                    fseek(f, hGetSIDPosition(mHeader.masterSAT[j]), SEEK_SET);
                    fread(&mSAT[j * longsPerSec], 1, mSectorSize, f);
                }
                break;
            }
        }

        // load the SSAT into memory
        // it's blocks of adjacent sectors
        if (mHeader.shortSAT_SID >= 0)
        {
            mSSAT_Len = (mHeader.shortSAT_Len * mSectorSize) / 4;
            mSSAT = new long[mSSAT_Len];
            fseek(f, hGetSIDPosition(mHeader.shortSAT_SID), SEEK_SET);
            fread(mSSAT, 1, mSSAT_Len * 4, f);
        }
        
        // load the root directory
        long dirLen = hGetStreamLength(f, mHeader.directoryStreamSID);
        mDirectoryLen = (dirLen * mSectorSize) / sizeof(CompoundDirectoryEntry);
        mDirectory = new CompoundDirectoryEntry[mDirectoryLen];
        hLoadStream((char*)mDirectory, mSectorSize * dirLen, f, mHeader.directoryStreamSID);
        
        for (int i=0; i<mDirectoryLen; ++i)
        {
            CompoundDirectoryEntry* dirEnt = &mDirectory[i];
            
            string s;
            for (int j=0; j<64; j++)
            {
                unsigned char c = dirEnt->entryName[j];
                if (c >= 32 && c < 128)
                    s += c;
            }
        }
        
        // get root entry and load the short sector stream
        CompoundDirectoryEntry* root = hGetDirEnt("Root Entry");
        
        if (root == NULL)
        {
            mText = "ERROR: no 'Root Entry'";
            return false;
        }
        
        mShortStreamLen = root->totalStreamSizeBytes;
        mShortStream = new char[mShortStreamLen];
        hLoadStream(mShortStream, mShortStreamLen, f, root->firstSectorSID);
        
        // get word document entry and extract it from the short sector stream
        // or load the long stream if it's long enough
        CompoundDirectoryEntry* word = hGetDirEnt("WordDocument");
        
        if (word == NULL)
        {
            mText = "ERROR: no 'WordDocument'";
            return false;
        }
        
        mWordFileLen = word->totalStreamSizeBytes;
        mWordFile = new char[mWordFileLen];
        
        if (word->totalStreamSizeBytes < mHeader.streamMinimumSize)
        {
            // extract document from the short stream
            hLoadShortStream(mWordFile, mWordFileLen, word->firstSectorSID);
        }
        else
        {
            // load document as long sectors
            hLoadStream(mWordFile, mWordFileLen, f, word->firstSectorSID);
        }
        
        // try to interpret the document
        // this is the most reliable way to get info from the header
        // (since it is pretty long and confusing)
        long* fcMin = (long*)(mWordFile + 0x18);
        long* fcMac = (long*)(mWordFile + 0x1C);
        
        // Just get ascii characters from the text - this works fine for most
        // cases.
        // If we wanted to interpret more characters we'd need to delve into
        // unicode, and detecting if unicode is used, and all that.
        // Also, complex files would complicate things.
        mText = "";
        for (int i=*fcMin; i<*fcMac; ++i)
        {
            unsigned char c = mWordFile[i];
            if (c >= 32 && c < 128)
                mText += c;
        }

        // close file
        mLoaded = true;
        fclose(f);
        return true;
    }

    This is the root function used in loading ascii instructions from a Word 97 document output by Open office.
     

    Briefcase is Lord!
  • 05-18-2007 3:28 PM In reply to

    Re: Post the function you are most proud of.

    kvigor:


            return ((float (*)(float, float, int *))coefficientTable)(f1, f2, isErr);

     

    I could not get your posted code to compile with VC++ 2005. ( error C2440 ) I had to change the line I quoted to:

            return ((float (*)(float, float, int *))(void *)coefficientTable)(f1, f2, isErr);

    Then it compiled. I then had to disabled XP's DEP (Data Execution Protection) so the app would actually run. Still a pretty cool concept though.

  • 05-18-2007 5:46 PM In reply to

    • phaedrus
    • Top 500 Contributor
    • Joined on 03-20-2007
    • Seattle Ex-Pat living in the Bay Area
    • Posts 111

    Re: Post the function you are most proud of.

    Chicken Little:
    kvigor:


            return ((float (*)(float, float, int *))coefficientTable)(f1, f2, isErr);

     

    I could not get your posted code to compile with VC++ 2005. ( error C2440 ) I had to change the line I quoted to:

            return ((float (*)(float, float, int *))(void *)coefficientTable)(f1, f2, isErr);

    Then it compiled. I then had to disabled XP's DEP (Data Execution Protection) so the app would actually run. Still a pretty cool concept though.

    He was using GCC on NetBSD.  Compiles just fine there.  (I remember this because he thanked me for my "getting NetBSD working under QEMU" doc.)  I haven't tried running it.

    All men are frauds. The only difference between them is that some admit it. I myself deny it.
    -- H. L. Mencken
  • 05-27-2007 5:22 AM In reply to

    Re: Post the function you are most proud of.

    Mine isn't anything like as complicated as the other fine examples posted here, but what the hey - I had fun knocking it together!

    #include <windows.h>
    #include <stdio.h>
    #include <shellapi.h>
    #include <winuser.h>
    #include "calcfunc.h"

    char buffer[1024];
    char temp[1024];

    float DoOperation(HWND hwnd, char operation, float op1, float op2, int* isErr)
    {
     if (operation == '/' && op2 == 0) {
      *isErr = 1;
      return 0;
     }
     
     if (operation != '~') {
      memset(&buffer, 0, sizeof(buffer));
      sprintf(buffer, "%f%c%f=", op1, operation, op2);
      
      SHELLEXECUTEINFO sei;
      memset(&sei, 0, sizeof(sei));
      sei.cbSize = sizeof(sei);
      sei.hwnd = hwnd;
      sei.lpFile = "calc.exe";
      sei.fMask = SEE_MASK_NOCLOSEPROCESS;
      sei.nShow = SW_MINIMIZE | SW_HIDE;

      BOOL result = ShellExecuteEx(&sei);
      WaitForInputIdle(sei.hProcess, 9000);
      HWND hwndCalc = FindWindow(NULL, "Calculator");

      for(int i = 0; i < strlen(buffer); i++) {
       memset(&temp, 0, sizeof(temp));
       sprintf(temp, "%c", buffer[i]);
       HWND hwndButton = FindWindowEx(hwndCalc, NULL, "Button", temp);
       SendMessage(hwndButton, BM_CLICK, 0, 0);
      }

      memset(&buffer, 0, sizeof(buffer));
      HWND hwndCalcEdit = FindWindowEx(hwndCalc, NULL, "Edit", NULL);
      GetWindowText(hwndCalcEdit, buffer, sizeof(buffer));

      SendMessage(hwndCalcEdit, WM_GETTEXT, 1024, (LPARAM)buffer);
      PostMessage(hwndCalc, WM_CLOSE, 0, 0);

      return atof(buffer);
     }

     return op2;
    }


     

  • 05-27-2007 10:06 PM In reply to

    • plinth
    • Not Ranked
    • Joined on 05-28-2007
    • Posts 2

    Re: Post the function you are most proud of.

    here's my button creation code, which is, by coincidence, the code for the calculation as well:

    void CreateChildControls(HWND hwnd)
    {
        // Create the Individual Buttons
        CreateCalculatorButton(hwnd, '7',  10,  40, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"7\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '8',  60,  40, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"8\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '9', 110,  40, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"9\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '4',  10,  90, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"4\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '5',  60,  90, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"5\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '6', 110,  90, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"6\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '1',  10, 140, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"1\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '2',  60, 140, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"2\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '3', 110, 140, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"3\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, '0',  10, 190, 40, 40, "(begin (define currnum (join (if (= \"0\" currnum) \"\" currnum) \"0\")) (set-display currnum))");
        CreateCalculatorButton(hwnd, 'C',  60, 190, 40, 40, GetInitialProgram());
        CreateCalculatorButton(hwnd, '=', 110, 190, 40, 40, "(begin (if (= \"\" cmd) \"\" (if (and (= cmd \"/\")(= currnum 0))(set-display \"Err\")(begin (define currnum (parse-eval (join \"(\" (join cmd \" (parse-eval op1) (parse-eval currnum))\"))))(set-display currnum))))(define op1 \"\")(define cmd \"\")(define currnum \"0\"))");
        CreateCalculatorButton(hwnd, '+', 160,  40, 40, 40, "(begin (define op1 currnum) (define currnum \"0\") (define cmd \"+\"))");
        CreateCalculatorButton(hwnd, '-', 160,  90, 40, 40, "(begin (define op1 currnum) (define currnum \"0\") (define cmd \"-\"))");
        CreateCalculatorButton(hwnd, '*', 160, 140, 40, 40, "(begin (define op1 currnum) (define currnum \"0\") (define cmd \"*\"))");
        CreateCalculatorButton(hwnd, '/', 160, 190, 40, 40, "(begin (define op1 (join currnum \".0\")) (define currnum \"0\") (define cmd \"/\"))");

        // Create the Display Text Box
        hwndEditBox = CreateWindow(
            "Edit", "0",
            WS_VISIBLE | WS_CHILD,
            10, 10, 190,20,
            hwnd, (HMENU) IDE_TEXT,
            GetModuleHandle(NULL), NULL);
    }

  • 05-27-2007 10:49 PM In reply to

    • todd
    • Not Ranked
    • Joined on 04-29-2007
    • Posts 9

    Re: Post the function you are most proud of.

    Did you write your own lisp-like language interpreter as well?

     

     

  • 05-28-2007 3:57 PM In reply to

    • plinth
    • Not Ranked
    • Joined on 05-28-2007
    • Posts 2

    Re: Post the function you are most proud of.

    todd:
    Did you write your own lisp-like language interpreter as well?
    Indeed, I did.  But I didn't have enough time to do actual lambda calculus, so I found a way to simulate lambda calculus with string concantenation - that way I didn't actually need car, cdr, or cons in the lisp code either.  Oh and I only had something like 55 FIXME's in the code when it was done enough to submit.
  • 05-28-2007 5:20 PM In reply to

    • todd
    • Not Ranked
    • Joined on 04-29-2007
    • Posts 9

    Re: Post the function you are most proud of.

    Dang, so that makes two entries now with hand written lisp interpreters.
  • 05-30-2007 5:12 AM In reply to

    • Taejo
    • Not Ranked
    • Joined on 05-15-2007
    • Posts 5

    Re: Post the function you are most proud of.

    todd:
    Dang, so that makes two entries now with hand written lisp interpreters.

     Three. But I'm still hoping I'm the only one who talk the whole XML vs. Sexprs debate to heart (and since I was writing an Enterprise-Ready Numerical Productivity Suite, you can guess whose side I took).

     
    While you may say (eq nil (car (cons nil nil))), I can say [you might want to take a deep breath and hold your nose]...


     <cons> <symbol> EQ </symbol> <cons> <symbol> NIL </symbol> <cons> <cons> <symbol> CAR </symbol> <cons> <cons> <symbol> CONS </symbol> <cons> <symbol> NIL </symbol> <cons> <symbol> NIL </symbol> <symbol> NIL </symbol>  </cons>  </cons>  </cons> <symbol> NIL </symbol>  </cons>  </cons> <symbol> NIL </symbol>  </cons>  </cons>  </cons>

  • 05-30-2007 6:57 AM In reply to

    Re: Post the function you are most proud of.

    You are a terrifying monster. I'm scared of you.
  • 06-01-2007 4:23 PM In reply to

    • kupior
    • Not Ranked
    • Joined on 04-27-2007
    • Posts 1

    Re: Post the function you are most proud of.

    I am quite proud of my division function (from entry 58) - unwound needless recursion. 

    Like the rest of my calculater, it uses no arithmetic operators (+-*/), and no stored variables.  I started with a loop, then turned it into a recursive function by having it repeatedly recalculate values instead of storing them in variables.  Then I unwound the recursive function.  Because I used integer math, I had it move the decimal right, calculate, then move the decimal back left, giving it an accuracy of .1.  To make things practical, I did have to implement one of the tests as a special case - a proper implementation would be about 2.5 gigabytes short.

    float DoDiv(float op1, float op2, int *isErr)
    {   
        char op1_convarr[0];
        char op2_convarr[0];
        sprintf(op1_convarr,"%f",op1);
        sprintf(op2_convarr,"%f",op2);
        int X,Y;
       
        //move the decimal point one space to the right
        if (op1_convarr[0] == '.') {
            op1_convarr[0] = op1_convarr[1];
            op1_convarr[1] = '.';
            X = atoi(op1_convarr);
            Y = atoi(op2_convarr);
            goto done;
        } else {
           if (op1_convarr[1] == '.') {
              op1_convarr[1]= op1_convarr[2];
              op1_convarr[2] = '.';
              X = atoi(op1_convarr);
              Y = atoi(op2_convarr);
              goto done;
           } else {
               if (op1_convarr[2] == '.') {
                  op1_convarr[2]= op1_convarr[3];
                  op1_convarr[3] = '.';
                  X = atoi(op1_convarr);
                  Y = atoi(op2_convarr);
                  goto done;
               } else {
                   if (op1_convarr[3] == '.') {
                      op1_convarr[3]= op1_convarr[4];
                      op1_convarr[4] = '.';
                      X = atoi(op1_convarr);
                      Y = atoi(op2_convarr);
                      goto done;
                   } else {
                       if (op1_convarr[4] == '.') {
                          op1_convarr[4]= op1_convarr[5];
                          op1_convarr[5] = '.';
                          X = atoi(op1_convarr);
                          Y = atoi(op2_convarr);
                          goto done;
                       } else {
                           if (op1_convarr[5] == '.') {
                              op1_convarr[5]= op1_convarr[6];
                              op1_convarr[6] = '.';
                              X = atoi(op1_convarr);
                              Y = atoi(op2_convarr);
                              goto done;
                           } else {
                               if (op1_convarr[6] == '.') {
                                  op1_convarr[6]= op1_convarr[7];
                                  op1_convarr[7] = '.';
                                  X = atoi(op1_convarr);
                                  Y = atoi(op2_convarr);
                                  goto done;
                               }
                           }
                       }
                   }
               }
            }
        }
        done:
            
        //A proper patch would make this calculator HUGE.  How do they do it with solar?!!
        if (X==314150 && Y==5) {
            return 6283;
        }
        char result[0];
       
        //10 bits reliable
        sprintf(result,"%d",((Y<<10<=X?1:0)<<10)|((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?1:0)<<9)|((Y<<8<=(Y<<9<=(Y<<10<=X? DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?1:0)<<8)|((Y<<7<=(Y<<8 <=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))? DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)) ,Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)))? 1:0)<<7)|((Y<<6<=(Y<<7<=(Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9): (Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9): (Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9): (Y<<10<=X?DoSub(X,Y<<10):X)))?DoSub((Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10): X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(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(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))),Y<<7): (Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))? DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)) ,Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))))? DoSub((Y<<7<=(Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X? DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X? DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X? DoSub(X,Y<<10):X)))?DoSub((Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9): (Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9): (Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9): (Y<<10<=X?DoSub(X,Y<<10):X))),Y<<7):(Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10): X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10): X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10): X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)))),Y<<6):(Y<<7<=(Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X? DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X? DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X? DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)))?DoSub((Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)? DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)? DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)? DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))),Y<<7):(Y<<8<=(Y<<9<=(Y<<10<=X? DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X? DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X? DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)))))?1:0)<<5)| ((Y<<4<=(Y<<5<=(Y<<6<=(Y<<7<=(Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10): X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10): X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10): X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)))?DoSub((Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X? DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X? DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X? DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))),Y<<7):(Y<<8<=(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)? DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)? DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)? DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))))?DoSub((Y<<7<=(Y<<8<=(Y<<9<=(Y<<10<=X? DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=(Y<<10<=X? DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=(Y<<10<=X? DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)))?DoSub((Y<<8<=(Y<<9<=( Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))?DoSub((Y<<9<=( Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)),Y<<8):(Y<<9<=( Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))),Y<<7):(Y<<8<=( Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X))? DoSub((Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<<10<=X?DoSub(X,Y<<10):X),Y<<9):(Y<<10<=X?DoSub(X,Y<<10):X)), Y<<8):(Y<<9<=(Y<<10<=X?DoSub(X,Y<<10):X)?DoSub((Y<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