mirror of
https://github.com/rm-dr/daisy
synced 2025-07-02 08:39:42 -07:00
Improved unit printing
This commit is contained in:
@ -48,6 +48,7 @@ impl ScalarBase for F64Base {
|
||||
foward!(fract);
|
||||
|
||||
fn is_zero(&self) -> bool {self.val == 0f64}
|
||||
fn is_one(&self) -> bool {self.val == 1f64}
|
||||
fn is_negative(&self) -> bool { self.val.is_sign_negative() }
|
||||
fn is_positive(&self) -> bool { self.val.is_sign_positive() }
|
||||
|
||||
|
@ -123,6 +123,7 @@ impl ScalarBase for FloatBase {
|
||||
foward!(fract);
|
||||
|
||||
fn is_zero(&self) -> bool {self.val.is_zero()}
|
||||
fn is_one(&self) -> bool {self.val == Float::with_val(FLOAT_PRECISION, 1)}
|
||||
fn is_negative(&self) -> bool { self.val.is_sign_negative() }
|
||||
fn is_positive(&self) -> bool { self.val.is_sign_positive() }
|
||||
|
||||
|
@ -24,6 +24,7 @@ pub trait ScalarBase:
|
||||
// Utility
|
||||
fn fract(&self) -> Option<Self>;
|
||||
fn is_zero(&self) -> bool;
|
||||
fn is_one(&self) -> bool;
|
||||
fn is_negative(&self) -> bool;
|
||||
fn is_positive(&self) -> bool;
|
||||
|
||||
@ -163,6 +164,13 @@ impl Scalar {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_one(&self) -> bool {
|
||||
match self {
|
||||
Scalar::Rational{v} => v.is_one(),
|
||||
Scalar::Float{v} => v.is_one(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_negative(&self) -> bool {
|
||||
match self {
|
||||
Scalar::Rational{v} => v.is_negative(),
|
||||
|
@ -110,6 +110,7 @@ impl ScalarBase for RationalBase {
|
||||
}
|
||||
|
||||
fn is_zero(&self) -> bool {self.val == Rational::from((0,1))}
|
||||
fn is_one(&self) -> bool {self.val == Rational::from((1,1))}
|
||||
fn is_negative(&self) -> bool { self.val.clone().signum() == -1 }
|
||||
fn is_positive(&self) -> bool { self.val.clone().signum() == 1 }
|
||||
|
||||
|
Reference in New Issue
Block a user