Skip to content

Compare floating-point spans by value - #125833

Open
xeemoff wants to merge 1 commit into
godotengine:masterfrom
xeemoff:fix/span-floating-point-equality
Open

xeemoff wants to merge 1 commit into
godotengine:masterfrom
xeemoff:fix/span-floating-point-equality

Conversation

@xeemoff

@xeemoff xeemoff commented Nov 26, 2026

Copy link
Copy Markdown

What problem(s) does this PR solve?

Span<float> and Span<double> used memcmp to compare their contents. This made spans containing +0.0 and -0.0 compare unequal. It also made spans containing NaNs with identical bits compare equal.

Additional information

Floating-point spans now compare their elements by value. The bytewise comparison is kept for matching integral types with unique object representations.

The regression test covers signed zero and NaN for both float and double. In an isolated run of the Godot Span tests, all four new assertions failed before the fix. All 16 assertions passed with the fix.

@Ivorforce Ivorforce left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't believe I missed this, but yes, it's correct. Notably makes nans unequal again, though most of them already are even now since there are multiple representations for nan.

@Ivorforce Ivorforce modified the milestones: 4.x, 4.8 Nov 26, 2026
@Ivorforce Ivorforce added cherrypick:4.6 Considered for cherry-picking into a future 4.6.x release cherrypick:4.7 Considered for cherry-picking into a future 4.7.x release labels Nov 26, 2026
Comment thread core/templates/span.h Resolved
@Ivorforce

Copy link
Copy Markdown
Member

Thanks! Now the PR needs to be squashed. Please see https://contributing.godotengine.org/en/latest/development/workflows/creating_pull_requests.html#the-interactive-rebase for more information.

@xeemoff
xeemoff force-pushed the fix/span-floating-point-equality branch from 9066eda to 45720c7 Compare November 26, 2026 10:35
@xeemoff

xeemoff commented Nov 26, 2026

Copy link
Copy Markdown
Author

@Ivorforce ✅ 45720c7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug cherrypick:4.6 Considered for cherry-picking into a future 4.6.x release cherrypick:4.7 Considered for cherry-picking into a future 4.7.x release topic:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants