Python, measuring distance using ray_cast
The location of hit loc is the local coordinate on the cube face that the ray hits.  

Its local distance from origin

(origin - loc).length


its global distance from origin

(mw * loc - src.matrix_world.translation).length


With no rotation or scale applied all local coordinates  on default cube are either 1 or -1.  The top and bottom faces are the planes z = 1 and z = -1 respectively.