Skip to content

Commit

Permalink
core(fixed): derive Ord, add some contants, add is_int()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Mar 2, 2024
1 parent c42362e commit fdb51dd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion wayrs-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl ArgValue {
}

/// Signed 24.8 decimal number
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Fixed(pub i32);

impl From<i32> for Fixed {
Expand Down Expand Up @@ -167,6 +167,10 @@ impl From<f64> for Fixed {
}

impl Fixed {
pub const ZERO: Self = Self(0);
pub const ONE: Self = Self(256);
pub const MINUS_ONE: Self = Self(-256);

pub fn as_f64(self) -> f64 {
self.0 as f64 / 256.0
}
Expand All @@ -178,6 +182,10 @@ impl Fixed {
pub fn as_int(self) -> i32 {
self.0 / 256
}

pub fn is_int(self) -> bool {
self.0 & 255 == 0
}
}

impl fmt::Debug for Fixed {
Expand Down

0 comments on commit fdb51dd

Please sign in to comment.