Skip to content
Snippets Groups Projects
Unverified Commit 057207c2 authored by Shaopeng Wang's avatar Shaopeng Wang Committed by GitHub
Browse files

Add is_positive and is_negative fn to Fixed128. (#121)

parent 9ac56d2f
No related branches found
No related tags found
No related merge requests found
...@@ -185,6 +185,14 @@ impl Fixed128 { ...@@ -185,6 +185,14 @@ impl Fixed128 {
*self *self
} }
} }
pub fn is_positive(&self) -> bool {
self.0.is_positive()
}
pub fn is_negative(&self) -> bool {
self.0.is_negative()
}
} }
impl Saturating for Fixed128 { impl Saturating for Fixed128 {
...@@ -553,4 +561,19 @@ mod tests { ...@@ -553,4 +561,19 @@ mod tests {
// saturating // saturating
assert_eq!(Fixed128::min_value().saturating_abs(), Fixed128::max_value()); assert_eq!(Fixed128::min_value().saturating_abs(), Fixed128::max_value());
} }
#[test]
fn is_positive_negative_should_work() {
let positive = Fixed128::from_parts(1);
assert!(positive.is_positive());
assert!(!positive.is_negative());
let negative = Fixed128::from_parts(-1);
assert!(!negative.is_positive());
assert!(negative.is_negative());
let zero = Fixed128::zero();
assert!(!zero.is_positive());
assert!(!zero.is_negative());
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment