avoid buffer overflow by rounding errors