Length of direct common tangent between the two non-intersecting Circles

Given two circles, of given radii, have there centres a given distance apart, such that the circles don’t touch each other. The task is to find the length of the direct common tangent between the circles.

Examples:

Input: r1 = 4, r2 = 6, d = 12 
Output: 11.8322

Input: r1 = 5, r2 = 9, d = 25
Output: 24.6779

Approach: