Fixed minus printing

This commit is contained in:
2023-04-02 08:27:21 -07:00
parent b5baaf293f
commit 038bbc5fde
4 changed files with 36 additions and 5 deletions

View File

@ -3,5 +3,5 @@ mod rationalq;
pub mod quantity;
pub use crate::quantity::quantity::Quantity;
const FLOAT_PRECISION: u32 = 2048;
const FLOAT_PRECISION: u32 = 1024;
const PRINT_LEN: usize = 5; // How many significant digits we will show in output

View File

@ -246,6 +246,20 @@ impl Quantity {
Quantity::Rational { .. } => {panic!()}
}
}
pub fn is_negative(&self) -> bool {
match self {
Quantity::Float { v } => {v.is_sign_negative() && v.is_normal()},
Quantity::Rational { v } => {v.is_negative()}
}
}
pub fn is_positive(&self) -> bool {
match self {
Quantity::Float { v } => {v.is_sign_positive() && v.is_normal()},
Quantity::Rational { v } => {v.is_positive()}
}
}
}
impl Neg for Quantity where {

View File

@ -86,6 +86,9 @@ impl RationalQ {
}
pub fn is_negative(&self) -> bool { self.val.clone().signum() == -1 }
pub fn is_positive(&self) -> bool { self.val.clone().signum() == 1 }
pub fn exp(&self) -> Quantity {float!(self.to_float().exp())}
pub fn abs(&self) -> Quantity {rational!(self.val.clone().abs())}