Update val to be min when less, max when greater.