Skip to content

fix(span): f64::content_eq return false for 0 and -0#9007

Merged
graphite-app[bot] merged 1 commit intomainfrom
02-10-fix_span_f64_content_eq_return_false_for_0_and_-0_
Feb 10, 2025
Merged

fix(span): f64::content_eq return false for 0 and -0#9007
graphite-app[bot] merged 1 commit intomainfrom
02-10-fix_span_f64_content_eq_return_false_for_0_and_-0_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Feb 10, 2025

Fixes #8982.

Previously 0f64.content_eq(-0f64) returned true. Now it returns false.

This also affects the behavior for NaN. Previously f64::NAN.content_eq(f64::NAN) returned false. Now it returns true. But it's complicated:

f64::NAN.content_eq(f64::NAN) == true
f64::NAN.content_eq(-f64::NAN) == false
f64::NAN.content_eq(--f64::NAN) == true

This does not align with JS's Object.is which returns true for any two NaN values.

If this matters, we could instead implement f64::content_eq as:

if self.is_nan() && other.is_nan() {
    true
} else {
    self.to_bits() == other.to_bits()
}

But this generates quite a lot of assembly for all f64 values, just to cover this small edge case with NaN: https://godbolt.org/z/q9zYodn4e

So I suggest that we go with it as in this PR for now, and see if NaN causes us problems in reality or not.

Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the C-bug Category - Bug label Feb 10, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 10, 2025

CodSpeed Performance Report

Merging #9007 will not alter performance

Comparing 02-10-fix_span_f64_content_eq_return_false_for_0_and_-0_ (81bed37) with main (beeb2fb)

Summary

✅ 33 untouched benchmarks

@overlookmotel overlookmotel marked this pull request as ready for review February 10, 2025 12:27
@overlookmotel overlookmotel requested a review from Boshen February 10, 2025 12:28
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Feb 10, 2025
Copy link
Member

Boshen commented Feb 10, 2025

Merge activity

  • Feb 10, 7:46 AM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 10, 7:46 AM EST: A user added this pull request to the Graphite merge queue.
  • Feb 10, 7:51 AM EST: A user merged this pull request with the Graphite merge queue.

Fixes #8982.

Previously `0f64.content_eq(-0f64)` returned `true`. Now it returns `false`.

This also affects the behavior for `NaN`. Previously `f64::NAN.content_eq(f64::NAN)` returned `false`. Now it returns `true`. But it's complicated:

```rs
f64::NAN.content_eq(f64::NAN) == true
f64::NAN.content_eq(-f64::NAN) == false
f64::NAN.content_eq(--f64::NAN) == true
```

This does *not* align with JS's `Object.is` which returns `true` for *any* two `NaN` values.

If this matters, we could instead implement `f64::content_eq` as:

```rs
if self.is_nan() && other.is_nan() {
    true
} else {
    self.to_bits() == other.to_bits()
}
```

But this generates quite a lot of assembly for all `f64` values, just to cover this small edge case with `NaN`: https://godbolt.org/z/q9zYodn4e

So I suggest that we go with it as in this PR for now, and see if `NaN` causes us problems in reality or not.
@graphite-app graphite-app bot force-pushed the 02-10-fix_span_f64_content_eq_return_false_for_0_and_-0_ branch from 9124225 to 81bed37 Compare February 10, 2025 12:46
@graphite-app graphite-app bot merged commit 81bed37 into main Feb 10, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 02-10-fix_span_f64_content_eq_return_false_for_0_and_-0_ branch February 10, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ast: ContentEq for -0 vs +0

2 participants