Improved unit printing

This commit is contained in:
2023-04-09 08:39:22 -07:00
parent 2fb25fb742
commit e9645208d9
6 changed files with 46 additions and 9 deletions

View File

@ -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() }

View File

@ -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() }

View File

@ -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(),

View File

@ -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 }