Round
function Round(E: Extended): LongInt;
Example
procedure ScriptEvent(var Value: variant);
begin
Value := Round(2.5); // normally 2 under nearest/even rounding
end;
Usage
Rounds an Extended value to the nearest 32-bit LongInt using the active floating-point rounding mode.
Parameters
| Name | Type | Description |
|---|---|---|
E | Extended | Floating value to round according to the active x87/SSE rounding mode. |
Returns
For a Velox-rounded value within Low(LongInt)..High(LongInt), the expected 32-bit integer. Values outside that range but still within Int64 silently wrap modulo 2^32 because Velox scripting.inc disables range/overflow checks in DefProc.
Velox Int64 result | Velox LongInt result |
|---|---|
2147483647 | 2147483647 |
2147483648 | -2147483648 |
4294967295 | -1 |
4294967296 | 0 |
Additional Technical Info
Round rounds an Extended value to an integer using Delphi System.Round, then stores only a PascalScript 32-bit LongInt result.
The default floating-point mode is nearest with ties to even (2.5 -> 2, 3.5 -> 4), but the wrapper does not force that mode. Its 32-bit unchecked narrowing is materially different from Delphi's documented Int64 result. The example is fictional and source-reviewed only.
Implementation
- The modified PascalScript compiler declares
Roundin the Numeric group. - Runtime
DefProcselector 18 reads anExtendedfrom the stack. - Delphi
System.Roundproduces anInt64according to the active floating-point mode. - Passing that value to
Stack.SetIntnarrows it toLongIntwith checks explicitly disabled.
Edge cases and errors
- Default midpoint behavior is nearest/even, not always away from zero.
- Code elsewhere in the process can change the floating-point rounding mode, altering results; Velox does not restore a known mode around this call.
- NaN, infinity or a rounded value outside Delphi's
Int64conversion range can raiseEInvalidOp/a math error before the 32-bit narrowing. Extendedis Double on default Win64 and wider on Win32, so borderline values can differ by target.- Do not use this function as a checked conversion. Validate the 32-bit range before calling if wraparound is unacceptable.
Related entries
Truncdiscards the fraction toward zero and has the same unchecked 32-bit narrowing.Round2BRscales a Double and uses Delphi Round before rescaling.Round2Upimplements midpoint-away-from-zero behavior through text for supported inputs.
External references
Created 2026-07-15