Maybe the MAX operator can do what you want.

Your check loop can be something like this:

max_value = old_speed MAX speed

old_speed = max_value

But this will lead eventually to a top value on max_value and you may have to reset this value. Don't know what you try to accomplish but a periodic reset may be needed.

Ioannis