Skip to main content

deterministic

Macro deterministic 

Source
macro_rules! deterministic {
    ($($body:tt)*) => { ... };
}
Expand description

Poka-Yoke macro to enforce Fixed32 in deterministic game logic (Bessey 2010).

This macro wraps a block and causes compile errors if f32/f64 literals are used. It works by shadowing the f32/f64 types with unconstructable struct types.

§Examples

use jugar_web::{deterministic, trace::Fixed32};

deterministic! {
    let a = Fixed32::from_int(5);
    let b = Fixed32::from_int(3);
    let result = a.mul(b);
    // This would cause a compile error:
    // let bad = 1.0f32 * 2.0;  // ERROR: f32 is shadowed
}

§Rationale

Per Monniaux (2008): “Floating-point non-determinism is a primary source of divergence in cross-platform replay systems.”

Per Bessey (2010): “Using compile-time constraints to enforce invariants catches bugs earlier than runtime checks.”