Skip to content

Preserve double precision when auto-converting integer assignments - #302

Open
fhgffy wants to merge 1 commit into
hyperrealm:masterfrom
fhgffy:fix/integer-float-conversion-precision
Open

fhgffy wants to merge 1 commit into
hyperrealm:masterfrom
fhgffy:fix/integer-float-conversion-precision

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 3, 2026

Copy link
Copy Markdown

Summary

With auto-conversion enabled, both integer setters cast through float before writing a floating-point setting's double storage. This loses precision unnecessarily: assigning 16777217 stores 16777216, although the original value is exactly representable as a double.

Convert directly to double, matching __config_setting_get_float. The change preserves the setting type and disabled-auto-conversion behavior.

The regression covers both setters, ordinary values, positive and negative values above float's exact-integer range, boundary neighbors, and rejected writes leaving the value unchanged.

Validation

Tested on Linux x86_64 with GCC 14.2 and CMake 4.4.3, based on 1e2dedd046f5119e67b0ccbda5916e8aff55c142:

  • Clean baseline: 17 native tests pass
  • Regression against unchanged implementation: the new test fails eight exact-value assertions; existing tests pass
  • Patched implementation: all 18 native tests pass; C/C++ libraries and examples build
  • ASan/UBSan: suite passes with leak detection disabled. LeakSanitizer could not run because of the environment's ptrace restriction
  • Additional local probes: C++ assignments and array elements, exact serialized output and parse-back, integer endpoints and values beyond double's exact range matching direct double conversion
  • git diff --check passes

Windows, macOS, 32-bit targets, embedded hardware, and Autotools builds were not tested locally. Normal integer-to-double rounding remains for values not exactly representable as double.

This branch has not been deployed

No deployments
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