gpui: Optimize coalesce float sign checking (#28072)

Optimize away a multiplication during in the `coalesce` function. Our
goal is to check whether the sign of two floats is the same.

Instead of multiplying each `.signum()` and checking that the result is
positive, we can simply check that the signum's are the same. This
removes a float multiplication.

```rust
a.signum() * b.signum() >= 0.0
```

turns into

```rust
a.signum() == b.signum()
```



Release Notes:

- Fix documentation for `Pixels::signum`
This commit is contained in:
tidely 2025-04-10 23:39:50 +03:00 committed by GitHub
parent 804066a047
commit 24d4f8ca18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View file

@ -2622,7 +2622,6 @@ impl Pixels {
/// Returns:
/// * `1.0` if the value is positive
/// * `-1.0` if the value is negative
/// * `0.0` if the value is zero
pub fn signum(&self) -> f32 {
self.0.signum()
}