# How would I figure out when a function would be at the "brink of underflow"?

User hardmath, provided an excellent overview of how to handle overflow when calculating the product of two functions, where one is likely to overflow: https://scicomp.stackexchange.com/a/20913/9466

The answer also discusses special cases involving $\textrm{erf}$ functions, which was discussed as an example in the question, so there is a discussion on handling $\textrm{erf}$ function underflow:

As a further precaution we will likely want to guard against underflow in evaluating $\operatorname{erfc}(x)$. The exponent range for double precision normal values goes down to binary (power of two) $-1022$. Asymptotically:

$$\operatorname{erfc}(x) \approx O(1/x) e^{-x^2}$$

Consequently we would be at the brink of exponent underflow when $x \approx 25$.

I would like to understand how to come up with the $x \approx 25$ value. I am likely missing some math background here, so it suffices to point me to the topics that would help me understand how to come up with such estimates,

In double-precision floating-point arithmetic, the number $2^{-1022}$ is the smallest (normal) positive number that can be represented. Computing any smaller positive number results in a loss of precision, as it cannot be represented as a floating-point value. This either means the computed number will be denormal (partial loss of precision) or possibly it could be rounded to zero (complete loss of precision).
In the case of erfc, you can solve for the largest $x$ such that $\mathrm{erfc}(x)$ does not underflow - such that $\mathrm{erfc}(x)$ can be represented with full accuracy. This is done by (numerically) solving the equation $$\mathrm{erfc}(x) = 2^{-1022}, \qquad\Longrightarrow\qquad x = 26.54,$$ or more easily by solving the approximate equation $$e^{-x^2}=2^{-1022}, \qquad\Longrightarrow\qquad x = \sqrt{1022\log 2} = 26.62.$$ The number $25$ then comes as a convenient estimate for when problems are likely to occur - most routines might start to give erroneous results before the actual limit.