import math


def haversine(lat1: float, lat2: float, lon1: float, lon2: float) -> float:
    """Calculate distance between two points on earth."""
    earth_radius = 6371e3
    phi1 = math.radians(lat1)
    phi2 = math.radians(lat2)
    delta_phi = math.radians(lat2 - lat1)
    delta_lam = math.radians(lon2 - lon1)
    a = (math.sin(delta_phi / 2) * math.sin(delta_phi / 2)
         + (math.cos(phi1) * math.cos(phi2)
            * math.sin(delta_lam / 2) * math.sin(delta_lam / 2)))
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    return earth_radius * c