Explanation:
the length and the width of a rectangle create a right-angled triangle, with the diagonal being the Hypotenuse of that triangle (the baseline, opposite of the 90° angle).
so, we can use Pythagoras
c² = a² + b²
with c being the Hypotenuse.
so, we have here
diagonal² = 40² + 9² = 1600 + 81 = 1681
diagonal = sqrt(1681) = 41 in