utils: Move NextDown
This commit is contained in:
parent
55d1ce5e3b
commit
61d44b3a9d
3 changed files with 30 additions and 30 deletions
|
|
@ -23,7 +23,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
SeatExt, Trigger,
|
SeatExt, Trigger,
|
||||||
},
|
},
|
||||||
utils::{prelude::*, quirks::workspace_overview_is_open},
|
utils::{float::NextDown, prelude::*, quirks::workspace_overview_is_open},
|
||||||
wayland::{
|
wayland::{
|
||||||
handlers::screencopy::SessionHolder,
|
handlers::screencopy::SessionHolder,
|
||||||
protocols::screencopy::{BufferConstraints, CursorSession},
|
protocols::screencopy::{BufferConstraints, CursorSession},
|
||||||
|
|
@ -2207,32 +2207,3 @@ fn mapped_output_for_device<'a, D: Device + 'static>(
|
||||||
};
|
};
|
||||||
map_to_output.or_else(|| shell.builtin_output())
|
map_to_output.or_else(|| shell.builtin_output())
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: When f64::next_down reaches stable rust, use that instead
|
|
||||||
trait NextDown {
|
|
||||||
fn next_lower(self) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NextDown for f64 {
|
|
||||||
fn next_lower(self) -> Self {
|
|
||||||
// We must use strictly integer arithmetic to prevent denormals from
|
|
||||||
// flushing to zero after an arithmetic operation on some platforms.
|
|
||||||
const NEG_TINY_BITS: u64 = 0x8000_0000_0000_0001; // Smallest (in magnitude) negative f64.
|
|
||||||
const CLEAR_SIGN_MASK: u64 = 0x7fff_ffff_ffff_ffff;
|
|
||||||
|
|
||||||
let bits = self.to_bits();
|
|
||||||
if self.is_nan() || bits == Self::NEG_INFINITY.to_bits() {
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
let abs = bits & CLEAR_SIGN_MASK;
|
|
||||||
let next_bits = if abs == 0 {
|
|
||||||
NEG_TINY_BITS
|
|
||||||
} else if bits == abs {
|
|
||||||
bits - 1
|
|
||||||
} else {
|
|
||||||
bits + 1
|
|
||||||
};
|
|
||||||
Self::from_bits(next_bits)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
28
src/utils/float.rs
Normal file
28
src/utils/float.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
// FIXME: When f64::next_down reaches stable rust, use that instead
|
||||||
|
pub trait NextDown {
|
||||||
|
fn next_lower(self) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NextDown for f64 {
|
||||||
|
fn next_lower(self) -> Self {
|
||||||
|
// We must use strictly integer arithmetic to prevent denormals from
|
||||||
|
// flushing to zero after an arithmetic operation on some platforms.
|
||||||
|
const NEG_TINY_BITS: u64 = 0x8000_0000_0000_0001; // Smallest (in magnitude) negative f64.
|
||||||
|
const CLEAR_SIGN_MASK: u64 = 0x7fff_ffff_ffff_ffff;
|
||||||
|
|
||||||
|
let bits = self.to_bits();
|
||||||
|
if self.is_nan() || bits == Self::NEG_INFINITY.to_bits() {
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
let abs = bits & CLEAR_SIGN_MASK;
|
||||||
|
let next_bits = if abs == 0 {
|
||||||
|
NEG_TINY_BITS
|
||||||
|
} else if bits == abs {
|
||||||
|
bits - 1
|
||||||
|
} else {
|
||||||
|
bits + 1
|
||||||
|
};
|
||||||
|
Self::from_bits(next_bits)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
pub mod env;
|
pub mod env;
|
||||||
mod ids;
|
mod ids;
|
||||||
pub(crate) use self::ids::id_gen;
|
pub(crate) use self::ids::id_gen;
|
||||||
|
pub mod float;
|
||||||
pub mod geometry;
|
pub mod geometry;
|
||||||
pub mod iced;
|
pub mod iced;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue