I'm not really worried about the performance of Math.min and Math.max fwiw. And I guess the code would be inlined if it runs often enough.