Cale pointed out the bug! I was using floating point division. What a bug!