calculate min/max