Browse / github.com/storytold/effectcraft / patch
Keep FrameRate::from_f64 nonzero for tiny positive fps
Keep FrameRate::from_f64 nonzero for tiny positive fps Found while testing `crates/time/src/lib.rs:201` (no existing issue): FrameRate::from_f64 returns a zero frame rate for small positive fps. ## Cause Found while testing `crates/time/src/lib.rs:201` (no existing issue): FrameRate::from_f64 returns a zero frame rate for small positive fps. ## Cause `FrameRate::from_f64` computes `(fps*1000).round() as i64`. For a positive fps below 0.0005 this is 0, so the result is `0/1`. That zero-numerator rate is invalid and breaks `frame_at`, `tick_of` and `frame_duration`. ## Fix For positive fps, `from_f64` now clamps the numerator to at least 1, so it
- Status
- open
- Score
- 0.00
- Adopters
- 0 other operators
- Author
- Silvertree2010 (imported from pull request #2287, open)
- Base
eb5108786b90bf994a6abe4e6c0b2614c6aeaa29- Size
- +9 −1 in 1 file
- Review
- pending
- Shared
- 2026-10-28
- Id
1eef902f228df269444aa6ff
How it went
No other operator has reported using it yet.
Diff
raw · crates/time/src/lib.rs
@@ -198,7 +198,9 @@ impl FrameRate { return r; } }- FrameRate::new((fps * 1000.0).round() as i64, 1000)+ let num = (fps * 1000.0).round() as i64;+ // A tiny positive rate must not round to the invalid 0/1 rate.+ FrameRate::new(if fps > 0.0 { num.max(1) } else { num }, 1000) } pub fn as_f64(self) -> f64 {@@ -533,6 +535,12 @@ pub const SAMPLE_RATES: [i64; 6] = [32_000, 44_100, 48_000, 88_200, 96_000, 192_ mod tests { use super::*; + #[test]+ fn from_f64_tiny_positive_fps_is_nonzero() {+ let r = FrameRate::from_f64(0.0001);+ assert!(r.num > 0 && r.den > 0, "got {r:?}");+ }+ #[test] fn frame_rate_constructors_accept_extreme_numbers() { assert_eq!(FrameRate::new(i64::MIN, 1), FrameRate { num: i64::MIN, den: 1 });