Native floating point to signed integers #
Lean defines the signed native casts through its logical floating-point models. 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 truncates FloatLib's exact finite value toward zero. Infinities map to
the caller's lower and upper endpoints, and NaN maps to zero.
Toward-zero signed conversion with Lean's native exceptional-value policy.
It 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 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. The checked failure keeps its sign, signaling class, and diagnostic payload without the quiet bit.
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.