converted linearize.c to integer math