TorchLean API

FloatLib.Floats.Formats.IEEE754.Native.Integer.ToInt

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.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.toInt_toModel_eq {fmt : FloatFormat} (hfmt : fmt.isIEEE = true) (x : Model fmt) (lower upper : ) :
Float.Model.UnpackedFloat.toInt lower upper x.toModel = match x.exactValue with | ExactValue.finite d => roundDyadicToInt IEEERoundingMode.towardZero d | ExactValue.infinity negative => if negative = true then lower else upper | ExactValue.nan sign signaling payload => 0

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

    Native binary64 to Int8 uses the shared toward-zero, saturation, and NaN-to-zero policy.

    Native binary32 to Int8 uses the shared toward-zero, saturation, and NaN-to-zero policy.