Underflow occurs when a float or double computation produces a value too close to zero to represent through its intermediate operations. Unlike integer overflow, it arises with extremely small floating-point values and may silently turn a nonzero expected result into zero. section 4.2.1
A tiny hypotenuse
For x = 3e-200 and y = 4e-200, Math.sqrt(x * x + y * y) returns zero rather than the expected 5e-200: squaring the inputs underflows before the square root runs. Use Math.hypot(x, y), which is designed to avoid this failure. section 4.2.1
Treat underflow pragmatically:
- Check calculations involving extremely small float or double values when a zero result would be significant. section 4.2.1
- Prefer Math.hypot for hypotenuse calculations instead of manually squaring very small operands. section 4.2.1
- Ignore it only when the application can safely tolerate the rare extremely-small-number case. section 4.2.1
