liveBook · Manning

Q7

As explained in Rust in Action: Systems programming concepts and techniques

Q7 is a one-byte signed fixed-point representation with seven value bits and one sign bit for compact fractional values.

Q7 is a one-byte fixed-point format for compactly representing fractional values from approximately −1 through 1. Seven bits encode the value and one sign bit encodes its sign. Unlike floating-point numbers, its decimal position stays fixed, trading accuracy for smaller storage. section 5.5

Conversions scale values by 128. Inputs at or above 1.0 become Q7(127), while inputs at or below −1.0 become Q7(−128); values inside the range are scaled and stored as i8. Converting back multiplies the stored integer by 2⁻⁷. f32 conversions pass through f64.

Check the representation

Run cargo test to verify f32-to-Q7 conversion, Q7-to-f32 conversion, and out-of-bounds saturation.

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Explains storage, scaling, saturation, Rust representation, conversions, and tests, but does not develop arithmetic operations.
Examples
Uses Rust definitions, f32 and f64 conversions, boundary inputs, and cargo test output.
What you can do after
Apply it via Rust by defining Q7 values and converting between Q7, f32, and f64.
How it connects
Connects fixed-point representation with floating-point numbers, quantization, tuple structs, traits, and integer storage.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.