EOverflow
Delphi Programming Language
Severity: ModerateWhat Does This Error Mean?
EOverflow is a Delphi floating-point exception raised when a calculation produces a result that is too large to store in the target floating-point type. Think of it like an odometer rolling past its maximum reading — the number is too big for the available digits. EOverflow is a sub-class of EMathError, which covers all floating-point arithmetic errors.
Affected Models
- All Delphi versions
- RAD Studio
- Applications performing floating-point calculations
Common Causes
- A floating-point calculation producing a result larger than approximately 1.18 × 10^4932 (Extended) or 1.8 × 10^308 (Double)
- Exponential growth in a loop — multiplying a float by a large factor many times causes the value to explode
- Calling Exp() or Power() with very large arguments — Exp(1000) produces a number far beyond any float type
- Accumulating very large values in a Sum or running total over many iterations without checking for overflow
- Receiving a very large number from a file, database, or external API and using it directly in calculations without range checking
How to Fix It
-
Find where the overflow occurs. The debugger or a crash log will point to the specific line. Print the input values going into the calculation to see which input is unexpectedly large.
Often the real bug is several steps earlier — a value that should have been normalised or capped was not.
-
Add range checks on input values before using them in calculations. If a value should not exceed a certain amount, check and cap or reject it before it reaches the floating-point operation.
Example: if Amount > MaxSafeAmount then raise Exception.Create('Amount exceeds maximum: ' + FloatToStr(Amount));
-
Replace calls to Exp(x) or Power(base, exponent) with checks that the arguments are within safe ranges. For Exp, arguments above about 11356 overflow Extended; above 709 overflow Double.
If you need to work with large exponents, use logarithms. Instead of comparing A > B^N, compare Ln(A) > N * Ln(B).
-
For accumulating large sums, use the Extended type (80-bit) instead of Double (64-bit). Extended holds significantly larger values and offers higher precision.
Declare as: var Total: Extended; — Extended is the largest native float type in Delphi and is only available on x86 platforms.
-
If overflow is expected and you want to handle it gracefully rather than raise an exception, use SetExceptionMask from the Math unit to mask EOverflow. The result will be Infinity instead of an exception.
Then check with IsInfinite(result) after the calculation and handle the infinite result appropriately.
When to Call a Professional
EOverflow is a code logic issue — the fix is always in your calculation or your input validation. For scientific computations involving extremely large numbers, consider using logarithmic arithmetic or arbitrary-precision libraries.
Frequently Asked Questions
What is the difference between EOverflow (EMathError) and integer overflow in Delphi?
EOverflow under EMathError is a floating-point overflow — the result is too large for a float type. Integer overflow is a different situation: Delphi raises EIntOverflow (a sub-class of EIntError) when overflow checking is enabled and an integer calculation wraps around. They are in different exception hierarchies. Floating-point overflow: EMathError → EOverflow. Integer overflow: EIntError → EIntOverflow.
What happens if I mask EOverflow — what does Infinity look like in Delphi?
Delphi's float types can hold the special values Infinity and Negative Infinity. You can check for them with IsInfinite(value) from the Math unit. Arithmetic on Infinity follows IEEE 754 rules: Infinity + 1 = Infinity, 1 / Infinity = 0, Infinity * 0 = NaN. If you pass Infinity to a function expecting a normal number, you will likely get more NaN or Infinity results cascading through your calculations.
How large can a Delphi Extended float actually get?
The Extended (80-bit) type can hold values up to approximately 1.18 × 10^4932. Double (64-bit) maxes out at about 1.8 × 10^308. Single (32-bit) maxes out at about 3.4 × 10^38. For comparison, the number of atoms in the observable universe is about 10^80 — well within Extended range but beyond Single.