Learning Objectives
By the end of this lesson you will be able to:
- State the key numeric boundaries of IEEE 754 double precision
- Explain the difference between overflow, underflow, and denormalization
- Design tests that probe the extreme limits of numeric fields
The Four Extreme Zones
For IEEE 754 double precision (Java double, JavaScript number):
Zone 1: Very Large Numbers (Overflow Territory)
- Maximum finite value:
1.7976931348623157 × 10^308 - Just above this: the value becomes
Infinity - Test input:
1.8e308,Double.MAX_VALUE + 1
Zone 2: Very Small Positive Numbers (Underflow Territory)
- Minimum normalized positive:
2.2250738585072014 × 10^-308 - Between this and zero: denormalized numbers (less precise)
- Minimum positive:
5 × 10^-324(nearly zero but not zero) - Below this: rounds to exactly
0.0 - Test input:
1e-324,1e-400(both round to 0.0 in double)
Zone 3: Negative Mirror
- Same ranges as positive but negative
- Test input:
-1.8e308(→ -Infinity)
Zone 4: Numbers Very Close to Zero
1e-300: extremely small but representable1e-400: underflows to exactly0.0- Danger: code that later divides by this will divide by zero!
The Underflow Trap
This is subtle and often missed:
User input: 0.000000000001 (1e-12, valid and representable)
User input: 1e-400 (underflows to 0.0 internally)
Both look like "very small numbers." But the second one becomes exactly zero when stored in a double. Any subsequent division by this value is division by zero.
A system that allows very small positive inputs must either:
- Accept them as-is and handle the resulting zero correctly
- Reject values below a reasonable minimum with a clear error
Test Values for Extreme Input Fields
| Test | Input Value | Expected Behavior |
|---|---|---|
| Max double | 1.7976931348623157e308 |
Accept and display/process |
| Just over max | 1.8e308 |
Reject or return Infinity (document which) |
| Very small | 1e-300 |
Accept |
| Near underflow | 5e-324 |
Accept (minimum positive double) |
| Underflow | 1e-400 |
Treat as 0 or reject |
| Negative mirror | -1.8e308 |
Reject or return -Infinity |
Pro Tip: When a specification says "the field accepts any positive number," that's your cue to test
1e-400(underflow to zero) and1e400(overflow to Infinity). The spec doesn't say these are invalid, but they will break most implementations.
Key Takeaways
- Double max ≈ 1.8×10^308; above this becomes Infinity
- Numbers below ≈ 5×10^-324 underflow to exactly 0.0 — dangerous for division
- Test both overflow and underflow boundaries for any "accepts any number" field
- Underflowed-to-zero values are division-by-zero accidents waiting to happen