TorchLean API

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

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.

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 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

    NaN maps to zero natively. The checked failure keeps its sign, signaling class, and diagnostic payload without the quiet bit.

    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.