calculate wrapped value with mod operator