It's calculated by the formula of Pythagoras.
d = √( (x1 - x2)2 + (y1 - y2)2 + (z1 - z2)2)
Take the plane E in normal form with the point P as position vector and the direction of the line g as normal vector. Determine the point of intersection S between this plane and the line g. The distance between S and P is the distance between the point and the line.
Intersect the plane by the perpendicular from the point to the plane and determine the distance between the point of intersection and the given point.