News for hackers. Stuff that matters.
Re:What every computer programmer should know about floating... by acqq on Tuesday September 16, 2014 @03:49AM (#8323467)
Without trying or thinking people just don't expect the effects which have sense once you know what is actually going on:

    void p( int i ) {
        float f = i;
        int i2 = f;
        printf( "%d\n%f\n%d\n\n", i, f, i2 );
    }
    int main() {
        p( 0x7fffffbf );
        p( 0x7fffffc0 );
    }

    /*
    prints
    
    2147483583
    2147483520.000000
    2147483520

    2147483584
    2147483648.000000
    -2147483648    
    */
I wouldn't call the behavior dumb, nor would I involve hate. You get the results that correspond to what you programmed, not what you wish to happen and what would actually not be feasible, as long as you insist on using float.

There are no comments on this comment yet.