function [mody] = jmod(x,y)

mody = rem(x,y);
mody(find(mody < 0)) = mody(find(mody < 0)) + y;