Skip to content

[#31] Add --hexfloat option to dump bit-exact float representations#114

Merged
SkowronskiAndrew merged 2 commits into
mainfrom
issue31-hexfloat
Jul 24, 2026
Merged

[#31] Add --hexfloat option to dump bit-exact float representations#114
SkowronskiAndrew merged 2 commits into
mainfrom
issue31-hexfloat

Conversation

@SkowronskiAndrew

Copy link
Copy Markdown
Collaborator

Summary

Fixes #31.

Tiny differences between float values get lost when they are converted to decimal, which makes them invisible when diffing two dumps. This adds the equivalent of binary2text's -hexfloat option: with -x / --hexfloat, every float and double value is followed by its bit-exact hexadecimal representation, in the same value(0xhex) format binary2text uses:

floatValue (float) 3.1415927(0x40490fdb)
doubleValue (double) 2.718281828459045(0x4005bf0a8b145769)

Note that binary2text only annotates 32-bit floats (double is a missing case in its output macro table); this implementation covers both float and double.

Changes

  • TextDumperTool: new HexFloat option, applied in ReadValue (scalars — which also covers compound types like Vector3f/ColorRGBA, whose components are float leaf nodes) and to basic-type array elements. Default output is unchanged, so the expected-data snapshots are untouched.
  • CLI: new -x / --hexfloat option on the dump command.
  • Tests: dump the SerializationDemo bundle with -x/--hexfloat and assert the known IEEE 754 bit patterns of its float and double fields (verified independently against python's struct.pack).
  • Documentation: option table entry and an example in command-dump.md.

Testing

dotnet test -c Release — full suite green (775 passed, 10 skipped, 0 failed).

Manually verified scalar fields, ColorRGBA components, and float array elements on the checked-in test data, and that default output is byte-identical to before.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a --hexfloat/-x option to the dump command to annotate float/double values with their IEEE-754 bit-exact hexadecimal representation (matching Unity’s binary2text -hexfloat style), improving diffability of dumps.

Changes:

  • Introduces a HexFloat flag in TextDumperTool and applies it to scalar float/double values and basic-type array elements.
  • Exposes -x / --hexfloat on the CLI dump command and wires it through to the dumper options.
  • Adds targeted tests asserting known float/double bit patterns, plus documentation updates for the new option.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
UnityDataTool/Program.cs Adds and wires the -x/--hexfloat CLI option into TextDumperTool.DumpOptions.
UnityDataTool.Tests/DumpTests.cs Adds a test verifying --hexfloat output includes expected IEEE-754 hex patterns.
TextDumper/TextDumperTool.cs Implements float/double formatting helpers and applies them to scalar reads + basic-type array dumps.
Documentation/command-dump.md Documents the new option and shows an example of the annotated output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TextDumper/TextDumperTool.cs Outdated
@SkowronskiAndrew
SkowronskiAndrew marked this pull request as ready for review July 24, 2026 20:30
@SkowronskiAndrew
SkowronskiAndrew merged commit 0f03442 into main Jul 24, 2026
5 checks passed
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.

"dump" command - Add "hex" option

2 participants