You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MDL writer: format_f64 emits "inf"/"-inf" for infinity values #325
format_f64() in src/simlin-engine/src/mdl/writer.rs (line 602-608) handles NaN correctly (falls through to Rust's default Display formatting which produces NaN) but has no special-case handling for positive or negative infinity. When f64::INFINITY or f64::NEG_INFINITY is passed in, Rust's Display trait emits inf and -inf respectively.
Vensim does not recognize inf/-inf as valid numeric literals. MDL files typically represent these cases using :NA: or very large sentinel numbers (e.g., 1e+38).
Current code:
fnformat_f64(v:f64) -> String{if v == v.trunc() && v.abs() < 1e15{format!("{}", v asi64)}else{format!("{}", v)}}
The v.abs() < 1e15 guard prevents the integer fast path for infinity (since f64::INFINITY.abs() is infinity, not less than 1e15), so it falls through to the else branch which emits inf.
Why it matters
Vensim compatibility: MDL files containing inf would fail to load in Vensim, breaking the roundtrip contract of the MDL writer.
Correctness: Even though infinity values are unlikely in practice (they could arise from division by zero in graphical function scales or other edge cases), the writer should produce valid MDL output for all possible floating-point inputs.
Component(s) affected
simlin-engine -- specifically src/simlin-engine/src/mdl/writer.rs, the format_f64() function
Possible approaches
Add explicit checks for v.is_infinite() before the existing logic, emitting :NA: (or a Vensim-compatible large number like 1e+38) for positive infinity and -1e+38 (or :NA:) for negative infinity.
Investigate what Vensim actually writes in these cases by examining real .mdl files and match that behavior.
Context
Identified during review of PR #324 (MDL writer implementation). The NaN case is already handled implicitly (Rust emits NaN which may also need attention), but infinity is the more immediately concerning case since it produces output Vensim cannot parse.
Activity