Here's a neat trick:
-(1/2) != -1/2
C & Fortran programmers are familiar with integer division truncating the result, so in C:
1/2 = -1/2 = 0
Python instead takes the floor of the result:
1/2 = 0
-1/2 = -1
Turns out this is an occasionally debated topic on comp.lang.python. The Python method has some argument for being more mathematically correct, but I bet it bites lots of C programmers!
It took me the better part of the afternoon to figure out what was wrong with some code I brought over from one of my C++ tools.
Oh well ... off to rebuild a 3 GB database :disgust:
-(1/2) != -1/2
C & Fortran programmers are familiar with integer division truncating the result, so in C:
1/2 = -1/2 = 0
Python instead takes the floor of the result:
1/2 = 0
-1/2 = -1
Turns out this is an occasionally debated topic on comp.lang.python. The Python method has some argument for being more mathematically correct, but I bet it bites lots of C programmers!
It took me the better part of the afternoon to figure out what was wrong with some code I brought over from one of my C++ tools.
Oh well ... off to rebuild a 3 GB database :disgust: