it was because integer division and modulo

integer division != Math.floor()