Skip to content

fix(value): compare integers without clamping - #391

Open
awais-ur-rehman wants to merge 1 commit into
flosch:masterfrom
awais-ur-rehman:feat/exact-integer-equality
Open

awais-ur-rehman wants to merge 1 commit into
flosch:masterfrom
awais-ur-rehman:feat/exact-integer-equality

Conversation

@awais-ur-rehman

Copy link
Copy Markdown

Summary

EqualValueTo now compares integer values without converting them through Integer(), which clamps large unsigned values to MaxInt. Distinct values such as MaxUint64 and MaxUint64-1 no longer compare equal or match each other in a template's in operator.

The Integer() conversion contract stays unchanged. Tests cover integer boundaries, both operand orders, aliases/pointers and actual template equality and membership.

Breaking Changes

None.

Testing

  • Full tests and race suite, go fmt, go vet and build pass with Go 1.26.10 on macOS arm64.
  • Configured lint reports the same 12 diagnostics as untouched master; no new diagnostics.
  • Ten interleaved equality benchmark samples show no significant timing change and remain at zero allocations.
  • An optional Linux/386 test compilation stops at two existing untyped-integer overflows, identical at the base commit; no 32-bit runtime validation is claimed.
  • Manual check: compare uint64(MaxUint64) with uint64(MaxUint64-1) in a template and check membership in a list containing only the first value; both comparisons should be false.

Codex assisted with implementation and tests.

- Compare signed and unsigned values without narrowing to int
- Cover large values, pointer aliases and template membership

BenchmarkValueEqualTo, 10 interleaved 100ms samples:
integers: 13.44ns -> 12.90ns (p=0.247)
strings: 21.93ns -> 22.07ns (p=0.288)
structs: 21.43ns -> 21.36ns (p=1.000)
slices: 11.87ns -> 11.89ns (p=0.642)
All remain at 0 B/op and 0 allocs/op.
@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.

1 participant