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
NaN/±Infinity float literals are emitted as undefined names (NaNf, -Infinity) in every target except JavaScript #159
The #96 fix (#147) only covers LiteralExpression<double>. In Coder/Languages/LanguageGeneratorBase.cs, doubles go through SpellNonFiniteDouble (L160-162), but floats go straight to FormatSingle (L164-166). FormatSingle (L1143-1144) writes the round-trip text unchanged when the value isn't finite. The C# generator also appends f (Coder/Languages/CSharpGenerator.cs:110-111).
The import check ContainsNonFiniteDouble (L448-449) looks only for LiteralExpression<double>. A non-finite float therefore never pulls in <math.h>, <limits>, or Go's "math" either.
Reproduction
A function that does return new LiteralExpression<float>(float.NaN) and declares a local float x = float.NegativeInfinity produces:
C#: NaNf / -Infinityf
Python, C++, C, Rust, Go: NaN / -Infinity, which are undefined identifiers and fail to compile or import
YAML save and load keeps the value (.nan, -.inf), so a reopened document keeps producing broken output.
Suggested fix / acceptance criteria
Spell non-finite floats per target. Either add a SpellNonFiniteSingle hook or route them through the double spelling with the target's single-precision form, e.g.:
C#: float.NaN / float.PositiveInfinity
Rust: f32::NAN / f32::INFINITY
C++: std::numeric_limits<float>::quiet_NaN()
C: NAN / INFINITY
Go: float32(math.NaN())
Python: float("nan")
Extend the import detection to LiteralExpression<float>.
Add float rows to NonFiniteDoubleLiteralTests for every generator, compiled or imported like the double rows.
Priority: Medium. Every target except JavaScript emits code that won't compile or import for a non-finite float literal, and YAML round-trips keep the bad value. It's limited to NaN/±Infinity floats, though.
Activity
matt-edmondson commentedon Oct 5, 2026
Triage
floatliteral, and YAML round-trips keep the bad value. It's limited to NaN/±Infinity floats, though.LanguageGeneratorBaseliteral spelling plus each generator's non-finite hook (the same area as the NaN and ±Infinity double literals are emitted as undefined identifiers (NaNd, Infinity, -Infinity) in every language except JavaScript #96/[patch] Spell NaN and infinity in each target language, with the import it needs #147 double fix).const X = math.NaN(), which does not compile #160 depends on this one: once floats are spelledfloat32(math.NaN())in Go, they need the sameconstexclusion.ContainsNonFiniteDoubleto cover floats, and add float rows toNonFiniteDoubleLiteralTests. Fixing this together with Go: constant field/local initialised to NaN or ±Infinity is emitted asconst X = math.NaN(), which does not compile #160 avoids touching the Go spelling twice.Generated by Claude Code