1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
use super::Fix;

/// Base-2 fixed-point types
pub mod bin {
    use typenum::*;

    /// Unsigned binary fixed-point type
    pub type UFix<B, E> = super::Fix<U2, B, E>;
    /// Signed binary fixed-point type
    pub type Fix<B, E> = super::Fix<P2, B, E>;

    /// Unsigned binary fixed-point type with 8-bits mantissa
    pub type UFix8<E> = UFix<P8, E>;
    /// Unsigned binary fixed-point type with 16-bits mantissa
    pub type UFix16<E> = UFix<P16, E>;
    /// Unsigned binary fixed-point type with 32-bits mantissa
    pub type UFix32<E> = UFix<P32, E>;
    /// Unsigned binary fixed-point type with 64-bits mantissa
    pub type UFix64<E> = UFix<P64, E>;

    #[cfg(feature = "i128")]
    /// Unsigned binary fixed-point type with 128-bits mantissa
    pub type UFix128<E> = UFix<P128, E>;

    /// Signed binary fixed-point type with 8-bits mantissa
    pub type Fix8<E> = Fix<P8, E>;
    /// Signed binary fixed-point type with 16-bits mantissa
    pub type Fix16<E> = Fix<P16, E>;
    /// Signed binary fixed-point type with 32-bits mantissa
    pub type Fix32<E> = Fix<P32, E>;
    /// Signed binary fixed-point type with 64-bits mantissa
    pub type Fix64<E> = Fix<P64, E>;

    #[cfg(feature = "i128")]
    /// Signed binary fixed-point type with 128-bits mantissa
    pub type Fix128<E> = Fix<P128, E>;
}

/// Base-10 fixed-point types
pub mod dec {
    use typenum::*;

    /// Unsigned decimal fixed-point type
    pub type UFix<B, E> = super::Fix<U10, B, E>;
    /// Signed decimal fixed-point type
    pub type Fix<B, E> = super::Fix<P10, B, E>;
}

/// SI prefixes.
pub mod si {
    use super::dec::{Fix, UFix};
    use typenum::{
        N1, N12, N15, N18, N2, N21, N24, N3, N6, N9, P1, P12, P15, P18, P2, P21, P24, P3, P6, P9,
        Z0,
    };

    /** Signed fixed ×10<sup>-24</sup> */
    pub type Yocto<B> = Fix<B, N24>;
    /** Signed fixed ×10<sup>-21</sup> */
    pub type Zepto<B> = Fix<B, N21>;
    /** Signed fixed ×10<sup>-18</sup> */
    pub type Atto<B> = Fix<B, N18>;
    /** Signed fixed ×10<sup>-15</sup> */
    pub type Femto<B> = Fix<B, N15>;
    /** Signed fixed ×10<sup>-12</sup> */
    pub type Pico<B> = Fix<B, N12>;
    /** Signed fixed ×10<sup>-9</sup> */
    pub type Nano<B> = Fix<B, N9>;
    /** Signed fixed ×10<sup>-6</sup> */
    pub type Micro<B> = Fix<B, N6>;
    /** Signed fixed ×10<sup>-3</sup> */
    pub type Milli<B> = Fix<B, N3>;
    /** Signed fixed ×10<sup>-2</sup> */
    pub type Centi<B> = Fix<B, N2>;
    /** Signed fixed ×10<sup>-1</sup> */
    pub type Deci<B> = Fix<B, N1>;

    /** Signed fixed ×10<sup>0</sup> */
    pub type Unit<B> = Fix<B, Z0>;

    /** Signed fixed ×10<sup>1</sup> */
    pub type Deca<B> = Fix<B, P1>;
    /** Signed fixed ×10<sup>2</sup> */
    pub type Hecto<B> = Fix<B, P2>;
    /** Signed fixed ×10<sup>3</sup> */
    pub type Kilo<B> = Fix<B, P3>;
    /** Signed fixed ×10<sup>6</sup> */
    pub type Mega<B> = Fix<B, P6>;
    /** Signed fixed ×10<sup>9</sup> */
    pub type Giga<B> = Fix<B, P9>;
    /** Signed fixed ×10<sup>12</sup> */
    pub type Tera<B> = Fix<B, P12>;
    /** Signed fixed ×10<sup>15</sup> */
    pub type Peta<B> = Fix<B, P15>;
    /** Signed fixed ×10<sup>18</sup> */
    pub type Exa<B> = Fix<B, P18>;
    /** Signed fixed ×10<sup>21</sup> */
    pub type Zeta<B> = Fix<B, P21>;
    /** Signed fixed ×10<sup>24</sup> */
    pub type Yotta<B> = Fix<B, P24>;

    /** Unsigned fixed ×10<sup>-24</sup> */
    pub type UYocto<B> = UFix<B, N24>;
    /** Unsigned fixed ×10<sup>-21</sup> */
    pub type UZepto<B> = UFix<B, N21>;
    /** Unsigned fixed ×10<sup>-18</sup> */
    pub type UAtto<B> = UFix<B, N18>;
    /** Unsigned fixed ×10<sup>-15</sup> */
    pub type UFemto<B> = UFix<B, N15>;
    /** Unsigned fixed ×10<sup>-12</sup> */
    pub type UPico<B> = UFix<B, N12>;
    /** Unsigned fixed ×10<sup>-9</sup> */
    pub type UNano<B> = UFix<B, N9>;
    /** Unsigned fixed ×10<sup>-6</sup> */
    pub type UMicro<B> = UFix<B, N6>;
    /** Unsigned fixed ×10<sup>-3</sup> */
    pub type UMilli<B> = UFix<B, N3>;
    /** Unsigned fixed ×10<sup>-2</sup> */
    pub type UCenti<B> = UFix<B, N2>;
    /** Unsigned fixed ×10<sup>-1</sup> */
    pub type UDeci<B> = UFix<B, N1>;

    /** Unsigned fixed ×10<sup>0</sup> */
    pub type UUnit<B> = UFix<B, Z0>;

    /** Unsigned fixed ×10<sup>1</sup> */
    pub type UDeca<B> = UFix<B, P1>;
    /** Unsigned fixed ×10<sup>2</sup> */
    pub type UHecto<B> = UFix<B, P2>;
    /** Unsigned fixed ×10<sup>3</sup> */
    pub type UKilo<B> = UFix<B, P3>;
    /** Unsigned fixed ×10<sup>6</sup> */
    pub type UMega<B> = UFix<B, P6>;
    /** Unsigned fixed ×10<sup>9</sup> */
    pub type UGiga<B> = UFix<B, P9>;
    /** Unsigned fixed ×10<sup>12</sup> */
    pub type UTera<B> = UFix<B, P12>;
    /** Unsigned fixed ×10<sup>15</sup> */
    pub type UPeta<B> = UFix<B, P15>;
    /** Unsigned fixed ×10<sup>18</sup> */
    pub type UExa<B> = UFix<B, P18>;
    /** Unsigned fixed ×10<sup>21</sup> */
    pub type UZeta<B> = UFix<B, P21>;
    /** Unsigned fixed ×10<sup>24</sup> */
    pub type UYotta<B> = UFix<B, P24>;
}

/// IEC prefixes.
pub mod iec {
    use super::bin::{Fix, UFix};
    use typenum::{P10, P20, P30, P40, P50, P60, P70, P80, Z0};

    /** Signed fixed ×2<sup>0</sup> */
    pub type Unit<B> = Fix<B, Z0>;

    /** Signed fixed ×2<sup>10</sup> */
    pub type Kibi<B> = Fix<B, P10>;
    /** Signed fixed ×2<sup>20</sup> */
    pub type Mebi<B> = Fix<B, P20>;
    /** Signed fixed ×2<sup>30</sup> */
    pub type Gibi<B> = Fix<B, P30>;
    /** Signed fixed ×2<sup>40</sup> */
    pub type Tebi<B> = Fix<B, P40>;
    /** Signed fixed ×2<sup>50</sup> */
    pub type Pebi<B> = Fix<B, P50>;
    /** Signed fixed ×2<sup>60</sup> */
    pub type Exbi<B> = Fix<B, P60>;
    /** Signed fixed ×2<sup>70</sup> */
    pub type Zebi<B> = Fix<B, P70>;
    /** Signed fixed ×2<sup>80</sup> */
    pub type Yobi<B> = Fix<B, P80>;

    /** Unsigned fixed ×2<sup>0</sup> */
    pub type UUnit<B> = UFix<B, Z0>;

    /** Unsigned fixed ×2<sup>10</sup> */
    pub type UKibi<B> = UFix<B, P10>;
    /** Unsigned fixed ×2<sup>20</sup> */
    pub type UMebi<B> = UFix<B, P20>;
    /** Unsigned fixed ×2<sup>30</sup> */
    pub type UGibi<B> = UFix<B, P30>;
    /** Unsigned fixed ×2<sup>40</sup> */
    pub type UTebi<B> = UFix<B, P40>;
    /** Unsigned fixed ×2<sup>50</sup> */
    pub type UPebi<B> = UFix<B, P50>;
    /** Unsigned fixed ×2<sup>60</sup> */
    pub type UExbi<B> = UFix<B, P60>;
    /** Unsigned fixed ×2<sup>70</sup> */
    pub type UZebi<B> = UFix<B, P70>;
    /** Unsigned fixed ×2<sup>80</sup> */
    pub type UYobi<B> = UFix<B, P80>;
}