Ad Space — Top Banner

Runtime Error 205

Delphi Programming

Severity: Moderate

What Does This Error Mean?

Runtime Error 205 is a floating-point overflow — a calculation produced a result larger than the floating-point type can represent. For example, raising a very large number to a high power, or dividing an extremely large value by a very small one near zero. Delphi raises this error when floating-point exception handling is enabled and an overflow condition occurs in the FPU.

Affected Models

  • Delphi 12 Athens
  • Delphi 11 Alexandria
  • Delphi 10.4 Sydney
  • Delphi 10.3 Rio
  • Delphi 10.2 Tokyo

Common Causes

  • Multiplying or raising very large floating-point values, producing a result beyond the type's maximum
  • Dividing a large number by a value very close to zero, approaching positive infinity
  • Accumulating rounding errors in a loop that cause a value to grow unboundedly
  • Using Single (7 significant digits) when Double or Extended precision is needed for the magnitude involved
  • Calling math functions like Exp() or Power() with arguments that produce astronomically large results

How to Fix It

  1. Identify the calculation that overflows by running in the debugger with a breakpoint set just before the suspected math operation. Inspect the intermediate values to see which operand is unexpectedly large.

    A Double can hold values up to approximately 1.8 × 10^308. A Single maxes out at about 3.4 × 10^38. If your calculation approaches these limits, overflow will occur.

  2. Guard against division by values near zero. Before dividing, check that the divisor is not dangerously small: if Abs(Divisor) < 1e-15 then ... handle zero case ... else Result := Numerator / Divisor;

    Dividing by 1e-300 when the numerator is 1e100 produces 1e400 — well beyond Double range.

  3. Use a larger floating-point type if the value range is legitimately large. Upgrade from Single to Double, or from Double to Extended (80-bit, available on Windows x86/x64).

    Single: ~7 decimal digits, max ~3.4×10^38. Double: ~15 digits, max ~1.8×10^308. Extended: ~18 digits, max ~1.2×10^4932.

  4. Validate inputs before passing them to functions like Exp(), Power(), or Sqr(). Apply a maximum cap: if X > MaxSafeValue then X := MaxSafeValue before calling Exp(X).

    Exp(710) already overflows a Double. Exp(1000) in a loop that increments by 1 each iteration will overflow very quickly.

  5. Use the Math unit's IsInfinite() and IsNan() functions to detect overflow results and handle them gracefully rather than letting them propagate through further calculations.

    After a suspect calculation: if IsInfinite(Result) or IsNan(Result) then Result := DefaultValue;

When to Call a Professional

Runtime Error 205 is fixable by reviewing the math in your calculation. Check for division by near-zero values and cap inputs before passing them to exponential or power functions. For scientific or financial calculations, use Extended or currency types with appropriate range validation.

Frequently Asked Questions

What is the difference between Runtime Error 205 and Runtime Error 215?

Runtime Error 205 is specifically a floating-point overflow — it occurs with Real, Single, Double, or Extended type variables. Runtime Error 215 is an integer arithmetic overflow — it occurs when integer arithmetic produces a result outside the bounds of the integer type. They involve different hardware units: 205 comes from the FPU (floating-point unit), while 215 comes from integer CPU instructions.

What happens to floating-point overflow without exception handling enabled?

Without FPU exception handling, overflow silently produces the special value +Infinity (or -Infinity). This infinity value then propagates through further calculations, corrupting all results that depend on it. You can check for infinity using the IsInfinite() function from Delphi's Math unit. Silent infinity propagation is often harder to debug than an explicit exception.

How does floating-point overflow differ from the EMathError exception class?

EMathError is the base class for all floating-point math exceptions in Delphi. EOverflow is a specific subclass of EMathError raised for floating-point overflow — it is the exception-class equivalent of Runtime Error 205. At the OS level these map to the same FPU overflow condition; the difference is whether you see the runtime error number or the exception class name depending on how your error handling is configured.