ebi/
traits.rs

1pub trait One: Sized {
2    fn one() -> Self;
3
4    fn set_one(&mut self) {
5        *self = One::one();
6    }
7
8    fn is_one(&self) -> bool;
9}
10
11pub trait Zero: Sized {
12    fn zero() -> Self;
13
14    fn set_zero(&mut self) {
15        *self = Zero::zero();
16    }
17
18    fn is_zero(&self) -> bool;
19}
20
21pub trait Signed: Sized {
22    fn abs(&self) -> Self;
23
24    /// Returns true if the number is positive and false if the number is zero or negative.
25    fn is_positive(&self) -> bool;
26
27    /// Returns true if the number is negative and false if the number is zero or positive.
28    fn is_negative(&self) -> bool;
29
30    /// For exact arithmetic: Returns true if the number is positive or zero.
31    /// For approximate arithmetic: returns true if the number is larger than -epsilon
32    fn is_not_negative(&self) -> bool;
33
34    /// For exact arithmetic: Returns true if the number is negative or zero.
35    /// For approximate arithmetic: returns true if the number is smaller than epsilon
36    fn is_not_positive(&self) -> bool;
37}
38
39pub trait Infinite: Signed {
40    /// Returns false if this value is positive infinity or negative infinity, and true otherwise.
41    fn is_finite(&self) -> bool {
42        !self.is_infinite()
43    }
44
45    /// Returns true if this value is positive infinity or negative infinity, and false otherwise.
46    fn is_infinite(&self) -> bool;
47
48    fn is_positive_infinite(&self) -> bool {
49        self.is_infinite() && self.is_positive()
50    }
51
52    fn is_negative_infinite(&self) -> bool {
53        self.is_infinite() && self.is_negative()
54    }
55}