Skip to content

Write whole-number doubles with a fraction so they stay floating-point - #90

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/78-double-literals
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/78-double-literals

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Part of #78. This is the core fix the triage comment separated out. Non-finite values are still open; see below.

What changed

  • Added LanguageGeneratorBase.FormatDouble. It formats with "R" and appends .0 when the text has no ., E or e and the value is finite. The shared literal path in TryGenerateCommonNode now calls it, which covers C, C++, Go, Rust, Python and JavaScript. 1.0 / 2.0 is now written as (1.0 / 2.0), where before it was (1 / 2). That was integer division (0) in C, C++ and Go and E0308 in Rust.
  • C# is unchanged. It already writes a d suffix, which makes 2d a double.
  • Added FloatingPointLiteralTests:
    • 1.0 / 2.0 keeps its fractions in all six generators.
    • Fractional and exponent values (0.5, -3.25, 1E+300, 0.1) are written unchanged.

Not in this PR (the issue stays open for it)

  • Per-language spellings of infinity and NaN (INFINITY/NAN, f64::INFINITY, math.Inf(1), float('inf'), …). Some of these need an include or import added, so they get their own change. Non-finite values are written the same as before, and .0 is not appended to them.
  • Parsing .inf, -.inf and .nan in YamlDeserializer.

Verification

  • Without the change, the new test fails: CGenerator wrote (1 / 2). With it, the test passes.
  • dotnet build: clean. Full suite: 910/910 pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_012B4b6sZaZ7tFJzNvax1B89


Generated by Claude Code

…t [patch]

A double literal was written with its round-trip text alone, so 2.0 became
2 and 1.0 / 2.0 became integer division in C, C++ and Go and a type error in
Rust. Part of #78.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012B4b6sZaZ7tFJzNvax1B89
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants