redgold_schema/
weighting.rs

1use crate::structs::Weighting;
2
3
4const CONVERSION: f64 = 1e3;
5
6impl Weighting {
7    pub fn to_float(&self) -> f64 {
8        (self.value as f64) / self.basis.map(|b| b as f64).unwrap_or(CONVERSION)
9    }
10    pub fn from_float(f: f64) -> Weighting {
11        Weighting {
12            value: (f * CONVERSION) as i64,
13            basis: None
14        }
15    }
16    pub fn from_float_basis(f: f64, basis: i64) -> Weighting {
17        Weighting {
18            value: (f * (basis as f64)) as i64,
19            basis: Some(basis)
20        }
21    }
22
23    pub fn from_int_basis(int: i64, basis: i64) -> Weighting {
24        Weighting {
25            value: int,
26            basis: Some(basis)
27        }
28    }
29
30}