Math Error
On this page, Math Error means the compiler raised a Delphi EMathError while pre-calculating a constant expression. The compiler handles integer and floating-point zero division first as Divide by Zero; this message is the remaining floating-point mathematical-exception path.
Safe correction pattern
There is no portable, deterministic failing expression to copy: the limit and exception behaviour can differ between 32-bit and 64-bit floating-point representations and control-word settings. Instead, reduce the magnitude or move a genuinely data-dependent calculation behind explicit validation.
procedure ScriptEvent(var Value: Variant);
const
SafeScale = 1.0E150;
begin
{ 1.0E300 is within the finite Double range. }
Value := SafeScale * SafeScale;
end;
Choose limits from the actual business domain rather than treating this sample value as a universal validation boundary.
How Velox detects it
The modified PascalScript compiler's PreCalc path asks its calculation helper to evaluate eligible constant operands. Its exception order is significant:
- Delphi
EDivByZeroandEZeroDividebecomeDivide by Zero. - Other Delphi
EMathErrordescendants becomeMath Error. - Other unexpected exceptions become
Internal error (<message>).
The compiler passes the caught exception message into ecMathError, but the public formatter ignores that parameter and returns only Math Error. The displayed text therefore does not reveal whether the underlying condition was overflow, underflow or another floating-point fault.
Correction procedure
- Inspect constant arithmetic near the reported position, including constants hidden by aliases and parentheses.
- Check multiplication, division and conversion ranges for the numeric type being produced.
- Reduce or rescale the expression without changing its business meaning.
- If values are genuinely runtime data, validate their range immediately before the operation and define a deliberate failure outcome.
- Recompile on the same Velox architecture that reported the error.
Edge cases and quirks
- This diagnostic concerns compile-time evaluation. Equivalent arithmetic involving a runtime variable follows the runtime exception path instead.
EMathErroris a Delphi exception family. Free Pascal has a similarly named compatibility class, but its floating-point modes and exception behaviour are not proof of Velox behaviour.- Real-number range differs by platform and representation. A literal or result accepted in one build can overflow in another.
- The lost exception detail makes the smallest constant subexpression the best diagnostic target.
- Constant folding does not perform business-domain checks such as permitted currency ranges; it only encounters host arithmetic behaviour.
Related reference
Divide by Zero- the two zero-divisor exception paths handled beforeEMathError.Internal error- unexpected non-mathematical exceptions during constant folding.Arithmetic (Math)- Velox numeric operators and result-type quirks.