use std::ops::*;
#[derive(PartialEq, Clone, Copy)]
pub enum BinaryPrefix<T> {
Unity(T),
Kibi(T),
Mebi(T),
Gibi(T),
Tebi(T),
Pebi(T),
Exbi(T),
Zebi(T),
Yobi(T),
}
impl<T: Copy + Shl<Output = T> + Into<u128>> BinaryPrefix<T> {
#[must_use = "This returns the result of the operation, without modifying the original."]
pub fn to_decimal_u128(&self) -> u128 {
match self {
BinaryPrefix::Unity(x) => { (*x).into() },
BinaryPrefix::Kibi(x) => { (*x).into() << 10 },
BinaryPrefix::Mebi(x) => { (*x).into() << 20 },
BinaryPrefix::Gibi(x) => { (*x).into() << 30 },
BinaryPrefix::Tebi(x) => { (*x).into() << 40 },
BinaryPrefix::Pebi(x) => { (*x).into() << 50 },
BinaryPrefix::Exbi(x) => { (*x).into() << 60 },
BinaryPrefix::Zebi(x) => { (*x).into() << 70 },
BinaryPrefix::Yobi(x) => { (*x).into() << 80 },
}
}
}
impl<T: Copy + Into<f64>> Into<f64> for BinaryPrefix<T> {
fn into(self) -> f64 {
match self {
BinaryPrefix::Unity(x) => { (x).into() },
BinaryPrefix::Kibi(x) => { (x).into() * BINARYCONVRATE[0] },
BinaryPrefix::Mebi(x) => { (x).into() * BINARYCONVRATE[1] },
BinaryPrefix::Gibi(x) => { (x).into() * BINARYCONVRATE[2] },
BinaryPrefix::Tebi(x) => { (x).into() * BINARYCONVRATE[3] },
BinaryPrefix::Pebi(x) => { (x).into() * BINARYCONVRATE[4] },
BinaryPrefix::Exbi(x) => { (x).into() * BINARYCONVRATE[5] },
BinaryPrefix::Zebi(x) => { (x).into() * BINARYCONVRATE[6] },
BinaryPrefix::Yobi(x) => { (x).into() * BINARYCONVRATE[7] },
}
}
}
impl<T: Copy + Into<f64>> Into<f32> for BinaryPrefix<T> {
#[must_use]
fn into(self) -> f32 {
match self {
BinaryPrefix::Unity(x) => { (x).into() as f32 },
BinaryPrefix::Kibi(x) => { ((x).into() * BINARYCONVRATE[0]) as f32 },
BinaryPrefix::Mebi(x) => { ((x).into() * BINARYCONVRATE[1]) as f32 },
BinaryPrefix::Gibi(x) => { ((x).into() * BINARYCONVRATE[2]) as f32 },
BinaryPrefix::Tebi(x) => { ((x).into() * BINARYCONVRATE[3]) as f32 },
BinaryPrefix::Pebi(x) => { ((x).into() * BINARYCONVRATE[4]) as f32 },
BinaryPrefix::Exbi(x) => { ((x).into() * BINARYCONVRATE[5]) as f32 },
BinaryPrefix::Zebi(x) => { ((x).into() * BINARYCONVRATE[6]) as f32 },
BinaryPrefix::Yobi(x) => { ((x).into() * BINARYCONVRATE[7]) as f32 },
}
}
}
impl<T: Copy + Shl<Output = T> + Into<u128>> Into<u128> for BinaryPrefix<T> {
fn into(self) -> u128 {
self.to_decimal_u128()
}
}
pub(crate) const BINARYCONVRATE: [f64; 8] = [1024.0,
1048576.0,
1073741824.0,
1099511627776.0,
1125899906842624.0,
1152921504606846976.0,
1180591620717411303424.0,
1208925819614629174706176.0];