Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Some of the most frustrating problems I've seen are due to misunderstanding or rare semantics rather than mistakes. Examples might include the specifics of floating-point math, or exactly how numeric coercion works. This is especially bad when the result isn't easy to eyeball as right or wrong.

For example, we could force a double-valued transcendental function to float and back for a small loss of precision in normal cases:

    #define sin(d) ((double)sinf(d))
Which yields...

    double i =  10
    --> i    =  10.0000000000
    sin(i)   = -0.5440211109
    sinf(i)  = -0.5440211296
    delta    =  0.0000000187
    
    double i =  0.25
    --> i    =  0.2500000000
    sin(i)   =  0.2474039593
    sinf(i)  =  0.2474039644
    delta    = -0.0000000051
    
    double i = 9999999.999999
    --> i    = 9999999.9999989998
    sin(i)   =  0.4205487007
    sinf(i)  =  0.4205478132
    delta    =  0.0000008875
(Format string was %25.10f, fwiw.)

Another idea: Let's say we know the application relies on rand() to produce the correct distribution for testing, or maybe to generate session keys. Changing the semantics of the RNG won't result in a compiler bug, but it might result in the tests failing to cover all cases, or a horrible security breach.



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: