mod function inplemented for intervals