Skip to main content

Crate renew_fixed

Crate renew_fixed 

Source
Expand description

Fixed-point arithmetic, for simulation code whose output has to reproduce bit-for-bit on every target.

§Why this crate exists

Rust guarantees IEEE 754 semantics for f32 and f64 operators, and that guarantee stops at the operators: sin, cos and their siblings are the platform’s maths library, and are permitted to differ between targets. A simulation that calls them has no cross-target claim to make.

Integer arithmetic is bit-identical everywhere, with nothing to police. That is the whole argument.

§Contract

  • Q47.16 in an i64. 16 fractional bits: a resolution of 2⁻¹⁶, and a range of ±2⁴⁷. See Fixed for why those numbers and not others.
  • No f32 or f64 in any signature this crate exposes. Converting to a float is a presentation concern, and the conversion is written at the boundary that needs it rather than offered here. It cannot be centralised in the maths crate: that crate is core and this one is optional, so the core-closure rule refuses the edge outright. Nor is centralising it worth much — each boundary carries its own precision-loss exemption with its own reason, and one shared helper would flatten those into a single reason that fits none of them. What stops a simulation from converting is not this contract but the float-arithmetic denial it already builds under.
  • Every operation is deterministic and target-independent. No operation here consults a clock, an allocator, an environment variable, or anything whose value could differ between two machines running the same build.
  • Overflow saturates, in every build profile, and is counted. Never wraps, never differs between debug and release. See [Fixed::saturations].

Structs§

Angle
An angle, as a fraction of a turn.
Fixed
A fixed-point number: Q47.16 in an i64.
Saturations
How many times arithmetic on this thread saturated.
Vec2
A two-dimensional vector.
Vec3
A three-dimensional vector. See Vec2 for the contract; it is the same.
Wide
A product of two Fixed values, kept at full width: Q95.32 in an i128.

Functions§

saturations
Read this thread’s saturation count.