use super::{UnitDef, reduce_den, reduce_num};
use core::marker::PhantomData;
pub trait Prefixable: UnitDef {}
macro_rules! define_prefixes {
($($(#[$meta:meta])* $prefix:ident, $symbol:literal, $num:literal / $den:literal;)*) => {
$(
$(#[$meta])*
pub struct $prefix<U> {
_phantom: PhantomData<U>,
}
impl<U: Prefixable> UnitDef for $prefix<U> {
type Dim = U::Dim;
const SCALE_NUM: i128 =
reduce_num(U::SCALE_NUM * $num, U::SCALE_DEN * $den);
const SCALE_DEN: i128 =
reduce_den(U::SCALE_NUM * $num, U::SCALE_DEN * $den);
const OFFSET_NUM: i128 = 0;
const OFFSET_DEN: i128 = 1;
const PREFIX: &'static str = $symbol;
const SYMBOL: &'static str = U::SYMBOL;
}
)*
};
}
define_prefixes! {
Quetta, "Q", 1_000_000_000_000_000_000_000_000_000_000 / 1;
Ronna, "R", 1_000_000_000_000_000_000_000_000_000 / 1;
Yotta, "Y", 1_000_000_000_000_000_000_000_000 / 1;
Zetta, "Z", 1_000_000_000_000_000_000_000 / 1;
Exa, "E", 1_000_000_000_000_000_000 / 1;
Peta, "P", 1_000_000_000_000_000 / 1;
Tera, "T", 1_000_000_000_000 / 1;
Giga, "G", 1_000_000_000 / 1;
Mega, "M", 1_000_000 / 1;
Kilo, "k", 1_000 / 1;
Hecto, "h", 100 / 1;
Deca, "da", 10 / 1;
Deci, "d", 1 / 10;
Centi, "c", 1 / 100;
Milli, "m", 1 / 1_000;
Micro, "u", 1 / 1_000_000;
Nano, "n", 1 / 1_000_000_000;
Pico, "p", 1 / 1_000_000_000_000;
Femto, "f", 1 / 1_000_000_000_000_000;
Atto, "a", 1 / 1_000_000_000_000_000_000;
Zepto, "z", 1 / 1_000_000_000_000_000_000_000;
Yocto, "y", 1 / 1_000_000_000_000_000_000_000_000;
Ronto, "r", 1 / 1_000_000_000_000_000_000_000_000_000;
Quecto, "q", 1 / 1_000_000_000_000_000_000_000_000_000_000;
}