FP32 is a single-precision floating-point format. Rust’s `f32` uses its 32 bits as three fields: a sign, an exponent, and a fraction. Together they represent a number, rather than an ordinary 32-bit integer. section 5.4.1
Figure 5.1 An overview of the three components encoded within the bits of a floating-point number for the f32 type in Rust
Use the bit-layout diagram to locate the three fields before extracting them in code. section 5.4.1
Take apart 42.42
As an `f32`, `42.42` has the bit pattern `0x4229AE14`. Call `to_bits()` to view it as a `u32`. Shift right by 23 and mask with `0xff` to isolate the eight exponent bits; subtract the bias, 127, to decode the exponent. The fraction bits contribute weighted powers of two to the mantissa. For this value, the decoded sign is positive, the exponent gives a factor of 32, and the mantissa is about 1.325625. section 5.4.1 section 5.4.3
That reconstruction describes ordinary values, not every bit pattern. An exponent field of all zeros permits subnormal values near zero; all ones marks infinities or NaNs. FP32 also has both positive and negative zero. These cases matter when comparing values: the two zeros compare equal, while a NaN does not compare equal to itself. section 5.4.4 section 5.8
Turn a byte into a probability-like value
For a byte `n`, `(n as f32) / 255.0` produces a value from 0 to 1. A bit-manipulation alternative places the byte into an `f32` fraction, constructs the value with `f32::from_bits()`, then scales it. That alternative maps `0xff` to `0.99609375`, not 1: check the endpoints before treating the two methods as interchangeable. section 5.6


