Skip to content

Read .inf, -.inf and .nan back as double literals - #95

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/78-yaml-non-finite-doubles
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/78-yaml-non-finite-doubles

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Part of #78. This covers the YAML half of what #90 left open. Per-language spellings of infinity and NaN are still to do, so the issue stays open.

What changed

YamlDotNet writes infinite and NaN doubles with the YAML core schema's spellings: .inf, -.inf and .nan. YamlDeserializer parsed double literals with double.TryParse, which doesn't accept those spellings. The literal was dropped, so double inf = +∞ came back as double inf; with no initialiser.

The Double case now goes through a small TryParseDouble helper. It reads every core-schema spelling of the non-finite values (.inf/.Inf/.INF, with an optional +, then -.inf and .nan in the same case variants) and falls back to the existing invariant double.TryParse for everything else.

Tests

NonFiniteDoubleSerializationTests:

  • round trip of +∞, -∞ and NaN literals keeps the value
  • a VariableDeclaration initialised to infinity keeps its initialiser after a round trip
  • each core-schema spelling deserializes to the right value

With the fix, 926/926 pass. With YamlDeserializer.cs reverted, all 13 new cases fail and the other 913 tests pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_015cCJCbaqmqLWvEB1Pep4Q9


Generated by Claude Code

The serializer writes infinite and NaN doubles with the YAML core schema's
spellings, which double.TryParse does not accept, so the deserializer dropped
the literal and a declaration initialised to infinity came back with no
initialiser. The deserializer now reads every core-schema spelling of the
non-finite values.

Part of #78

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015cCJCbaqmqLWvEB1Pep4Q9
@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