Native floating point to signed integers #
Lean 4.34 gives the signed native casts logical definitions using the floating-point models introduced in Lean 4.33. They truncate toward zero, saturate overflow and infinities, and send NaN to zero. FloatLib's checked conversion reports those exceptional cases as errors.
The shared policy below uses the same exact decoder and integral rounder as the checked
conversion. In-range means that the truncated integer is in range: for example, 127.75
converts successfully to the signed eight-bit integer 127.
Lean's integer conversion reads FloatLib's exact interpretation and truncates its finite dyadic. Infinity endpoints are supplied by the destination; NaN maps to zero before saturation.
Toward-zero signed conversion with Lean's native exceptional-value policy.
This uses the checked conversion's exact decoder and integral rounder, then saturates finite overflow. Infinities select their signed endpoint and NaN selects zero.
Instances For
The native policy is the existing saturating integer encoder applied to Lean's model result.
Checked conversion agrees with native saturation whenever its rounded integer is in range.
On an in-range truncated integer, native saturation and the checked API return the same code.
Out-of-range finite values saturate natively but are rejected by the checked conversion.
Infinity saturates to its signed endpoint while the checked API reports signed infinity.
NaN maps to zero natively while the checked API reports its payload.
Native binary64 to ISize saturates to the platform's signed interval.
Native binary32 to Int8 uses the shared toward-zero, saturation, and NaN-to-zero policy.
Native binary32 to ISize saturates to the platform's signed interval.