Skip to content

Format YAML doubles with shortest round-trip and compare floats numerically in YamlMatcher - #2478

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1028480496
Open

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1028480496

Conversation

@copybara-service

Copy link
Copy Markdown

Format YAML doubles with shortest round-trip and compare floats numerically in YamlMatcher

  • Update EnvConfigToYaml to serialize double variable defaults using
    std::to_chars (std::chars_format::general) with a %.17g fallback and
    YAML 1.2 .nan/.inf/-.inf literals, avoiding trailing precision noise
    (e.g., 3.1400000000000001) while preserving full IEEE-754 precision.
  • Update EqualsYaml in yaml_matcher.cc to compare unquoted/!!float YAML
    float scalars numerically as double (with NaN == NaN), while keeping
    exact string comparison for quoted strings, !!str, and pure integers.
  • Add unit tests in env_yaml_test.cc and yaml_matcher_test.cc.

…ically in YamlMatcher

- Update `EnvConfigToYaml` to serialize `double` variable defaults using
  `std::to_chars` (`std::chars_format::general`) with a `%.17g` fallback and
  YAML 1.2 `.nan`/`.inf`/`-.inf` literals, avoiding trailing precision noise
  (e.g., `3.1400000000000001`) while preserving full IEEE-754 precision.
- Update `EqualsYaml` in `yaml_matcher.cc` to compare unquoted/`!!float` YAML
  float scalars numerically as `double` (with `NaN == NaN`), while keeping
  exact string comparison for quoted strings, `!!str`, and pure integers.
- Add unit tests in `env_yaml_test.cc` and `yaml_matcher_test.cc`.

PiperOrigin-RevId: 1028480496
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.

1 participant