fn leaseclock_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn leaseclock_compute(issued: f64, ttl: f64, now: f64) -> vector { if now < issued { return []; } let age = now - issued; if age < ttl { return [1, ttl - age, 0]; } [0, 0, age - ttl] } // Classify a message lease against a single monotonic clock. // Returns [active, remaining ticks, overdue ticks]. A lease expires exactly at its TTL; clocks earlier than issuance are invalid. pub fn leaseclock_remaining(issued: f64, ttl: f64, now: f64) -> vector { if !(issued >= 0.0 && issued <= 9007199254740991.0 && issued % 1.0 == 0.0) { return []; } if !(ttl >= 1.0 && ttl <= 9007199254740991.0 && ttl % 1.0 == 0.0) { return []; } if !(now >= 0.0 && now <= 9007199254740991.0 && now % 1.0 == 0.0) { return []; } let result = leaseclock_compute(issued, ttl, now); if !leaseclock_finite(result) { return []; } result }