Program that adds all natural numbers and yields -1/12
C

Should work on platforms where both sizeof(float) and sizeof(int) are 4 and follows the IEEE floating point standard (I guess).

Version 1:



#define toFloat(x) (*(float*)&amp;x)
#define ABS(x)     (x&lt;0 ? (-x) : x)
#include &lt;stdio.h&gt;
int main() {
    unsigned int sum=0;
    int i=1;
    /* Since we really can't sum to infinity,
     * we sum it until it is very close to -1/12, within 3 decimal places.
     * Need to convert sum to float since -1/12 is not int                 */
    while(!(ABS(toFloat(sum) + 1./12) &lt;= 0.001)) {
        sum+=i;
        i++;
    }
    printf("%.3f\n", toFloat(sum));
    return 0;
}


Output: -0.083

Explanation:


   Not a very interesting answer, but with misleading comments.  The sum from 1 to 79774 is 3181985425, which has the same binary representation as -0.082638867199420928955078125 when interpreted as a float instead of an unsigned int.  Note that !(abs&lt;=0.001) is used instead of abs&gt;0.001 to avoid quitting the loop when the sum reaches 2139135936 (NaN in float). (Thanks to @CodesInChaos for suggesting this idea instead of an independent isNaN check.)


Special thanks to @Geobits for the idea of terminating the loop by comparing the sum instead of the counter.

Edit: Version 2

#include &lt;stdio.h&gt;
const float inf = 1./0.;
int main() {
    int x=1;
    int sum=0xBDAAAAAB; // Arbitrary magic number for debugging
    while(x --&gt; inf) { // while x tends to infinity (?)
        sum+=x;
    }
    float sumf=*(float*)&amp;sum; // convert to float since -1/12 is not int
    if(sumf == 0xBDAAAAAB) { // no sum performed, something's wrong with the loop...
        fprintf(stderr, "sum is unchanged\n");
        return -1;
    }
    printf("%f\n", sumf);
    return 0;
}


Output: -0.083333

Explanation:


   Uses the same int-to-float trick, but with the --&gt; "tends to" operator here. Since every number is smaller than infinity the loop will not be executed even once.  After converting to float it is compared with the int magic number (i.e. -0.83333 is compared with 0xBDAAAAAB, or 3182078635), which of course is different.