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 and ±Infinity double literals are emitted as undefined identifiers (NaNd, Infinity, -Infinity) in every language except JavaScript #96
LanguageGeneratorBase.FormatDouble (Coder/Languages/LanguageGeneratorBase.cs) formats with ToString("R") and, as its remarks say, leaves a non-finite value "as it is". CSharpGenerator writes {value.ToString(InvariantCulture)}d (Coder/Languages/CSharpGenerator.cs:105-106). Neither maps NaN or infinity to a spelling the target language understands.
Repro
gen.Generate(Literal.DecimalValue(double.NaN)), and the same for PositiveInfinity and NegativeInfinity:
Target
Emitted
Result
C#
NaNd, Infinityd, -Infinityd
not a valid token
C / C++
NaN, Infinity
gcc: 'NaN' undeclared
Go
NaN
undefined: NaN
Rust
NaN
E0425 cannot find value NaN
Python
NaN
NameError: name 'NaN' is not defined
JavaScript
NaN, Infinity
correct
These results come from compiling the generated text with each real toolchain.
Why it matters
NaN and infinity are common sentinel and default values, for example const double Unset = NaN or an initial min = Infinity. Any AST that contains one produces code that fails to compile in 6 of the 7 targets, and nothing warns about it at generation time.
Suggested fix
Add a per-language hook for non-finite values, such as a virtual FormatDouble or a FormatNonFinite(double):
Language
NaN
+Inf / −Inf
C#
double.NaN
double.PositiveInfinity / double.NegativeInfinity
C++
std::numeric_limits<double>::quiet_NaN()
std::numeric_limits<double>::infinity() (negated)
C
NAN
INFINITY / -INFINITY (needs <math.h>)
Go
math.NaN()
math.Inf(1) / math.Inf(-1) (needs import "math")
Rust
f64::NAN
f64::INFINITY / f64::NEG_INFINITY
Python
float("nan")
float("inf") / float("-inf")
JavaScript
NaN
Infinity / -Infinity
The C and Go spellings also need an include or import. If the generators can't add one yet, they should throw NotSupportedException rather than emit an undefined name.
Acceptance: a data-driven test covers NaN, +∞ and −∞ for each generator.
Next reader: add the per-language non-finite hook and the "required imports" mechanism in SourceFile generation, then add the data-driven NaN/+∞/−∞ test for each generator. Close this issue and #78 together.
Activity
matt-edmondson commentedon Sep 27, 2026
Triage
LanguageGeneratorBase.FormatDoubleandCSharpGenerator. Owner: @matt-edmondson, who is already assigned to Whole-number double literals are emitted as integers: 1.0/2.0 becomes integer division (0) in C/C++/Go and fails to compile in Rust #78..inf/.nanread-back and says the per-language spellings are still to do. This issue gives a more complete spec for that remaining part, with the full per-language table and the include/import caveat for C and Go. Either close it as a duplicate of Whole-number double literals are emitted as integers: 1.0/2.0 becomes integer division (0) in C/C++/Go and fails to compile in Rust #78, or narrow Whole-number double literals are emitted as integers: 1.0/2.0 becomes integer division (0) in C/C++/Go and fails to compile in Rust #78 to whole-number formatting and track the non-finite spellings here.Generated by Claude Code
matt-edmondson commentedon Sep 28, 2026
Decision (maintainer, 2026-09-28)
NAN/INFINITYplus<math.h>), the C++ spelling (std::numeric_limitsplus<limits>) and the Go spelling (math.NaN()/math.Inf(±1)plusimport "math") are emitted together with their import. The generator does not throwNotSupportedExceptionfor them.double.NaN/double.PositiveInfinityrather thanNaNd.Next reader: add the per-language non-finite hook and the "required imports" mechanism in
SourceFilegeneration, then add the data-driven NaN/+∞/−∞ test for each generator. Close this issue and #78 together.Generated by Claude Code