You could take a look at Vincenty's formulae https://en.wikipedia.org/wiki/Vincenty's_formulae

If you want to see an implementation of geodetic distance, you could take a look at PostGIS's function here: https://github.com/postgis/postgis/b...odetic.c#L2084