wasm_num_trunc (wasm v0.1.0)
View SourceFloat to integer truncation, both families. Read this if a conversion traps where you expected a clamp, or the other way round.
The two families differ only in what they do when the value does not fit:
i32.trunc_f32_sand friends trap on NaN and on out-of-range values.i32.trunc_sat_f32_sand friends saturate: NaN becomes 0, and out-of-range values clamp to the nearest representable bound.
The range test is the subtle part. It must be done against the exact real
bound, not the rounded one: f32 cannot represent 2^31-1, so testing
V =< 2147483647.0 would wrongly accept 2147483648.0, which rounds to the
same float. The correct test is strict against the next power of two, which
is exactly representable. Truncation happens first, so the comparison is on
the already-truncated value.
Summary
Types
-type fspecial() :: infinity | neg_infinity | {nan, Sign :: 0 | 1, Payload :: non_neg_integer()}.