Skip to content

NaN/±Infinity float literals are emitted as undefined names (NaNf, -Infinity) in every target except JavaScript #159

Closed

Description

@matt-edmondson

What's wrong

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.

Activity

  1. added
    bug
    on Oct 5, 2026
  2. matt-edmondson commented on Oct 5, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions