Added more units

This commit is contained in:
2023-04-13 20:11:20 -07:00
parent ce2217e7f9
commit b2a809ea8b
8 changed files with 245 additions and 85 deletions

View File

@ -25,25 +25,20 @@ pub struct RationalBase where {
pub val: Rational
}
/*
fn to_string_radix(&self, radix: i32, num_digits: Option<usize>) -> String {
self.to_float().to_string_radix(radix, num_digits)
}
fn to_sign_string_exp(&self, radix: i32, num_digits: Option<usize>) -> (bool, String, Option<i32>) {
self.to_float().to_sign_string_exp(radix, num_digits)
}
*/
impl ToString for RationalBase{
fn to_string(&self) -> String {
return self.val.to_string();
}
}
impl RationalBase {
pub fn from_frac(t: i64, b: i64) -> Option<RationalBase> {
let v = Rational::from((t, b));
return Some(RationalBase{ val: v });
}
}
impl ScalarBase for RationalBase {
fn from_f64(f: f64) -> Option<RationalBase> {
let v = Rational::from_f64(f);
if v.is_none() { return None }

View File

@ -116,6 +116,12 @@ impl Scalar {
return Some(wrap_rational!(r.unwrap()));
}
pub fn new_rational_from_frac(t: i64, b: i64) -> Option<Self> {
let r = RationalBase::from_frac(t, b);
if r.is_none() { return None; }
return Some(wrap_rational!(r.unwrap()));
}
pub fn new_float_from_string(s: &str) -> Option<Self> {
let v = FloatBase::from_string(s);
if v.is_none() { return None; }