Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TotalEq -0 in fabs test #294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

TotalEq -0 in fabs test #294

wants to merge 1 commit into from

Conversation

Rudxain
Copy link

@Rudxain Rudxain commented Apr 11, 2024

assert_eq! uses PartialEq, which doesn't discern between -0 and +0. total_cmp does distinguish them. So this patch makes the test spec-compliant

@Rudxain
Copy link
Author

Rudxain commented Apr 11, 2024

I recommend reviewing any other code that uses == and/or assert_eq!, to check if it should be replaced by total_cmp. total_cmp also distinguishes between signed NANs, which may be useful somewhere else in the codebase

@Amanieu
Copy link
Member

Amanieu commented Apr 11, 2024

It would be better to use .to_bits() to ensure an exact match.

@Rudxain
Copy link
Author

Rudxain commented Apr 11, 2024

.to_bits()

I agree, but that would only apply to other cases (such as performance-sensitive code), not here. The spec imposes no requirements about fabs return bit pattern

@Amanieu
Copy link
Member

Amanieu commented Apr 12, 2024

There is only a single bit pattern for 0 or -0.

@Rudxain
Copy link
Author

Rudxain commented Apr 12, 2024

There is only a single bit pattern for 0 or -0.

Yes, but some platforms use "flush-to-zero" for subnormal numbers. I'm not entirely sure how that mechanism works 🤔

@Amanieu
Copy link
Member

Amanieu commented Apr 12, 2024

That doesn't have any effect here. It's only done during arithmetic operations, not comparisons. In any case the Rust language doesn't allow flush-to-zero behavior, so such modes must be turned off in the CPU when running Rust code.

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.

2 participants