I'm not quite sure how the current equation was derived. But the case clearly fails for the case that the width and height are both equal to one, for example.
int x = 0;
int y = 0;
int width = 1;
int height = 1;
float u = (x / (width - 1)); // 0 / (1 - 1) = 0 / 0 = NaN
float v = (y / (height - 1));
Should be changed to:
float u = (x + 0.5f) / width;
float v = (y + 0.5f) / height;
The result can be seen clearly when you can a 2x2 image as an example.
The UV coordinates previously would be:
(0, 0) (1, 0)
(0, 1) (1, 1)
The correct result would be:
(0.25, 0.25) (0.75, 0.25)
(0.25, 0.75) (0.75, 0.75)