Added function for fitting a value into a given range.