Implement the softmax function based on the provided mathematical formula.
Given a non-empty list of real-valued logits, return a list of probabilities in the same order. Use a numerically stable implementation that avoids overflow for large logits. The output probabilities should sum to approximately 1, within normal floating-point tolerance.
Function signature: def softmax(logits): Input is list[float]; output is list[float].
def softmax(logits):