wraps the mod result to avoid negative results.