If you know the ratio is 16:9, you can do a little algebra:
h = 16*x
v = 9*x
x = h/16
sqrt((h*h) + (v*v)) = sqrt((16*16*x*x) + (9*9*x*x))
= sqrt((16*16+9*9)*x*x)
= sqrt(16*16+9*9)*x
= sqrt(16*16+9*9)*h/16
= sqrt(16*16+9*9)/16 * h
pre-compute sqrt(16*16+9*9)/16
:
static float const multiplier = std::sqrt(16*16+9*9)/16.0;
and use
float const d = multiplier*h;