hexga_math/other/
prefix.rs

1//! Contains some common prefix, such as `[Kilo]`, `[Milli]`, `[Tera]`
2use super::*;
3
4/// 10^15 = 1_000_000_000_000_000
5pub trait PrefixPeta : Sized 
6{ 
7    /// 10^15 = 1_000_000_000_000_000
8    const PETA : Self;
9    /// multiply by 10^15 = 1_000_000_000_000_000
10    fn peta(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::PETA  } 
11}
12impl PrefixPeta for f64 { const PETA : Self = 1_000_000_000_000_000.; }
13impl PrefixPeta for f32 { const PETA : Self = 1_000_000_000_000_000.; }
14impl PrefixPeta for u64 { const PETA : Self = 1_000_000_000_000_000 ; }
15impl PrefixPeta for i64 { const PETA : Self = 1_000_000_000_000_000 ; }
16impl_composite_constant!(PrefixPeta, PETA);
17
18
19/// 10^15 = 1_000_000_000_000_000
20pub trait PrefixQuadrillion : Sized 
21{ 
22    /// 10^15 = 1_000_000_000_000_000
23    const QUADRILLION : Self;
24    /// multiply by 10^15 = 1_000_000_000_000_000
25    fn quadrillion(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::QUADRILLION  } 
26}
27impl PrefixQuadrillion for f64 { const QUADRILLION : Self = 1_000_000_000_000_000.; }
28impl PrefixQuadrillion for f32 { const QUADRILLION : Self = 1_000_000_000_000_000.; }
29impl PrefixQuadrillion for u64 { const QUADRILLION : Self = 1_000_000_000_000_000 ; }
30impl PrefixQuadrillion for i64 { const QUADRILLION : Self = 1_000_000_000_000_000 ; }
31impl_composite_constant!(PrefixQuadrillion, QUADRILLION);
32
33
34
35/// 10^12 = 1_000_000_000_000
36pub trait PrefixTera : Sized 
37{ 
38    /// 10^12 = 1_000_000_000_000
39    const TERA : Self;
40    /// multiply by 10^12 = 1_000_000_000_000
41    fn tera(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::TERA  } 
42}
43impl PrefixTera for f64 { const TERA : Self = 1_000_000_000_000.; }
44impl PrefixTera for f32 { const TERA : Self = 1_000_000_000_000.; }
45impl PrefixTera for u64 { const TERA : Self = 1_000_000_000_000 ; }
46impl PrefixTera for i64 { const TERA : Self = 1_000_000_000_000 ; }
47impl_composite_constant!(PrefixTera, TERA);
48
49
50/// 10^12 = 1_000_000_000_000
51pub trait PrefixTrillion : Sized 
52{ 
53    /// 10^12 = 1_000_000_000_000
54    const TRILLION : Self;
55    /// multiply by 10^12 = 1_000_000_000_000
56    fn trillion(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::TRILLION  } 
57}
58impl PrefixTrillion for f64 { const TRILLION : Self = 1_000_000_000_000.; }
59impl PrefixTrillion for f32 { const TRILLION : Self = 1_000_000_000_000.; }
60impl PrefixTrillion for u64 { const TRILLION : Self = 1_000_000_000_000 ; }
61impl PrefixTrillion for i64 { const TRILLION : Self = 1_000_000_000_000 ; }
62impl_composite_constant!(PrefixTrillion, TRILLION);
63
64
65
66
67
68/// 10^9 = 1_000_000_000
69pub trait PrefixGiga : Sized 
70{ 
71    /// 10^9 = 1_000_000_000
72    const GIGA : Self;
73    /// multiply by 10^9 = 1_000_000_000
74    fn giga(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::GIGA  } 
75}
76impl PrefixGiga for usize { const GIGA : Self = 1_000_000_000 ; }
77impl PrefixGiga for isize { const GIGA : Self = 1_000_000_000 ; }
78impl PrefixGiga for f64   { const GIGA : Self = 1_000_000_000.; }
79impl PrefixGiga for f32   { const GIGA : Self = 1_000_000_000.; }
80impl PrefixGiga for u64   { const GIGA : Self = 1_000_000_000 ; }
81impl PrefixGiga for i64   { const GIGA : Self = 1_000_000_000 ; }
82impl PrefixGiga for u32   { const GIGA : Self = 1_000_000_000 ; }
83impl PrefixGiga for i32   { const GIGA : Self = 1_000_000_000 ; }
84impl_composite_constant!(PrefixGiga, GIGA);
85
86
87/// 10^9 = 1_000_000_000
88pub trait PrefixBillion : Sized 
89{ 
90    /// 10^9 = 1_000_000_000
91    const BILLION : Self;
92    /// multiply by 10^9 = 1_000_000_000
93    fn billion(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::BILLION  } 
94}
95impl PrefixBillion for usize { const BILLION : Self = 1_000_000_000 ; }
96impl PrefixBillion for isize { const BILLION : Self = 1_000_000_000 ; }
97impl PrefixBillion for f64   { const BILLION : Self = 1_000_000_000.; }
98impl PrefixBillion for f32   { const BILLION : Self = 1_000_000_000.; }
99impl PrefixBillion for u64   { const BILLION : Self = 1_000_000_000 ; }
100impl PrefixBillion for i64   { const BILLION : Self = 1_000_000_000 ; }
101impl PrefixBillion for u32   { const BILLION : Self = 1_000_000_000 ; }
102impl PrefixBillion for i32   { const BILLION : Self = 1_000_000_000 ; }
103impl_composite_constant!(PrefixBillion, BILLION);
104
105
106
107
108/// 10^6 = 1_000_000
109pub trait PrefixMega : Sized 
110{ 
111    /// 10^6 = 1_000_000
112    const MEGA : Self;
113    /// multiply by 10^6 = 1_000_000
114    fn mega(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::MEGA  } 
115}
116impl PrefixMega for usize { const MEGA : Self = 1_000_000 ; }
117impl PrefixMega for isize { const MEGA : Self = 1_000_000 ; }
118impl PrefixMega for f64   { const MEGA : Self = 1_000_000.; }
119impl PrefixMega for f32   { const MEGA : Self = 1_000_000.; }
120impl PrefixMega for u64   { const MEGA : Self = 1_000_000 ; }
121impl PrefixMega for i64   { const MEGA : Self = 1_000_000 ; }
122impl PrefixMega for u32   { const MEGA : Self = 1_000_000 ; }
123impl PrefixMega for i32   { const MEGA : Self = 1_000_000 ; }
124impl_composite_constant!(PrefixMega, MEGA);
125
126
127
128/// 10^6 = 1_000_000
129pub trait PrefixMillion : Sized 
130{ 
131    /// 10^6 = 1_000_000
132    const MILLION : Self;
133    /// multiply by 10^6 = 1_000_000
134    fn million(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::MILLION  } 
135}
136impl PrefixMillion for usize { const MILLION : Self = 1_000_000 ; }
137impl PrefixMillion for isize { const MILLION : Self = 1_000_000 ; }
138impl PrefixMillion for f64   { const MILLION : Self = 1_000_000.; }
139impl PrefixMillion for f32   { const MILLION : Self = 1_000_000.; }
140impl PrefixMillion for u64   { const MILLION : Self = 1_000_000 ; }
141impl PrefixMillion for i64   { const MILLION : Self = 1_000_000 ; }
142impl PrefixMillion for u32   { const MILLION : Self = 1_000_000 ; }
143impl PrefixMillion for i32   { const MILLION : Self = 1_000_000 ; }
144impl_composite_constant!(PrefixMillion, MILLION);
145
146
147
148/// 10^3 = 1_000
149pub trait PrefixKilo : Sized 
150{ 
151    /// 10^3 = 1_000
152    const KILO : Self;
153    /// multiply by 10^3 = 1_000
154    fn kilo(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::KILO  } 
155}
156impl PrefixKilo for usize { const KILO : Self = 1_000 ; }
157impl PrefixKilo for isize { const KILO : Self = 1_000 ; }
158impl PrefixKilo for f64   { const KILO : Self = 1_000.; }
159impl PrefixKilo for f32   { const KILO : Self = 1_000.; }
160impl PrefixKilo for u64   { const KILO : Self = 1_000 ; }
161impl PrefixKilo for i64   { const KILO : Self = 1_000 ; }
162impl PrefixKilo for u32   { const KILO : Self = 1_000 ; }
163impl PrefixKilo for i32   { const KILO : Self = 1_000 ; }
164impl PrefixKilo for u16   { const KILO : Self = 1_000 ; }
165impl PrefixKilo for i16   { const KILO : Self = 1_000 ; }
166impl_composite_constant!(PrefixKilo, KILO);
167
168
169/// 10^3 = 1_000
170pub trait PrefixThousand : Sized 
171{ 
172    /// 10^3 = 1_000
173    const THOUSAND : Self;
174    /// multiply by 10^3 = 1_000
175    fn thousand(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::THOUSAND  } 
176}
177impl PrefixThousand for usize { const THOUSAND : Self = 1_000 ; }
178impl PrefixThousand for isize { const THOUSAND : Self = 1_000 ; }
179impl PrefixThousand for f64   { const THOUSAND : Self = 1_000.; }
180impl PrefixThousand for f32   { const THOUSAND : Self = 1_000.; }
181impl PrefixThousand for u64   { const THOUSAND : Self = 1_000 ; }
182impl PrefixThousand for i64   { const THOUSAND : Self = 1_000 ; }
183impl PrefixThousand for u32   { const THOUSAND : Self = 1_000 ; }
184impl PrefixThousand for i32   { const THOUSAND : Self = 1_000 ; }
185impl PrefixThousand for u16   { const THOUSAND : Self = 1_000 ; }
186impl PrefixThousand for i16   { const THOUSAND : Self = 1_000 ; }
187impl_composite_constant!(PrefixThousand, THOUSAND);
188
189
190
191/// 10^2 = 100
192pub trait PrefixHecto : Sized 
193{ 
194    /// 10^2 = 100
195    const HECTO : Self;
196    /// multiply by 10^2 = 100
197    fn hecto(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::HECTO  } 
198}
199
200impl PrefixHecto for usize { const HECTO : Self = 100 ; }
201impl PrefixHecto for isize { const HECTO : Self = 100 ; }
202impl PrefixHecto for f64   { const HECTO : Self = 100.; }
203impl PrefixHecto for f32   { const HECTO : Self = 100.; }
204impl PrefixHecto for u64   { const HECTO : Self = 100 ; }
205impl PrefixHecto for i64   { const HECTO : Self = 100 ; }
206impl PrefixHecto for u32   { const HECTO : Self = 100 ; }
207impl PrefixHecto for i32   { const HECTO : Self = 100 ; }
208impl PrefixHecto for u16   { const HECTO : Self = 100 ; }
209impl PrefixHecto for i16   { const HECTO : Self = 100 ; }
210impl PrefixHecto for u8    { const HECTO : Self = 100 ; }
211impl PrefixHecto for i8    { const HECTO : Self = 100 ; }
212impl_composite_constant!(PrefixHecto, HECTO);
213
214
215
216/// 10^2 = 100
217pub trait PrefixHundred : Sized 
218{ 
219    /// 10^2 = 100
220    const HUNDRED : Self;
221    /// multiply by 10^2 = 100
222    fn hundred(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::HUNDRED  } 
223}
224
225impl PrefixHundred for usize { const HUNDRED : Self = 100 ; }
226impl PrefixHundred for isize { const HUNDRED : Self = 100 ; }
227impl PrefixHundred for f64   { const HUNDRED : Self = 100.; }
228impl PrefixHundred for f32   { const HUNDRED : Self = 100.; }
229impl PrefixHundred for u64   { const HUNDRED : Self = 100 ; }
230impl PrefixHundred for i64   { const HUNDRED : Self = 100 ; }
231impl PrefixHundred for u32   { const HUNDRED : Self = 100 ; }
232impl PrefixHundred for i32   { const HUNDRED : Self = 100 ; }
233impl PrefixHundred for u16   { const HUNDRED : Self = 100 ; }
234impl PrefixHundred for i16   { const HUNDRED : Self = 100 ; }
235impl PrefixHundred for u8    { const HUNDRED : Self = 100 ; }
236impl PrefixHundred for i8    { const HUNDRED : Self = 100 ; }
237impl_composite_constant!(PrefixHundred, HUNDRED);
238
239
240
241/// 10^1 = 10
242pub trait PrefixDeca : Sized 
243{ 
244    /// 10^1 = 10
245    const DECA : Self;
246    /// multiply by 10^1 = 10
247    fn deca(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::DECA  } 
248}
249
250impl PrefixDeca for usize { const DECA : Self = 10 ; }
251impl PrefixDeca for isize { const DECA : Self = 10 ; }
252impl PrefixDeca for f64   { const DECA : Self = 10.; }
253impl PrefixDeca for f32   { const DECA : Self = 10.; }
254impl PrefixDeca for u64   { const DECA : Self = 10 ; }
255impl PrefixDeca for i64   { const DECA : Self = 10 ; }
256impl PrefixDeca for u32   { const DECA : Self = 10 ; }
257impl PrefixDeca for i32   { const DECA : Self = 10 ; }
258impl PrefixDeca for u16   { const DECA : Self = 10 ; }
259impl PrefixDeca for i16   { const DECA : Self = 10 ; }
260impl PrefixDeca for u8    { const DECA : Self = 10 ; }
261impl PrefixDeca for i8    { const DECA : Self = 10 ; }
262impl_composite_constant!(PrefixDeca, DECA);
263
264
265
266
267/// 10^1 = 10
268pub trait PrefixDecade : Sized 
269{ 
270    /// 10^1 = 10
271    const DECADE : Self;
272    /// multiply by 10^1 = 10
273    fn decade(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::DECADE  } 
274}
275
276impl PrefixDecade for usize { const DECADE : Self = 10 ; }
277impl PrefixDecade for isize { const DECADE : Self = 10 ; }
278impl PrefixDecade for f64   { const DECADE : Self = 10.; }
279impl PrefixDecade for f32   { const DECADE : Self = 10.; }
280impl PrefixDecade for u64   { const DECADE : Self = 10 ; }
281impl PrefixDecade for i64   { const DECADE : Self = 10 ; }
282impl PrefixDecade for u32   { const DECADE : Self = 10 ; }
283impl PrefixDecade for i32   { const DECADE : Self = 10 ; }
284impl PrefixDecade for u16   { const DECADE : Self = 10 ; }
285impl PrefixDecade for i16   { const DECADE : Self = 10 ; }
286impl PrefixDecade for u8    { const DECADE : Self = 10 ; }
287impl PrefixDecade for i8    { const DECADE : Self = 10 ; }
288impl_composite_constant!(PrefixDecade, DECADE);
289
290
291
292/// 10^-1 = 1/10
293pub trait PrefixDeci : Sized 
294{ 
295    /// 10^-1 = 1/10
296    const DECI : Self;
297    /// multiply by 10^-1 = 1/10
298    fn deci(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::DECI  } 
299}
300impl PrefixDeci for f64   { const DECI : Self = 1. / 10.; }
301impl PrefixDeci for f32   { const DECI : Self = 1. / 10.; }
302impl_composite_constant!(PrefixDeci, DECI);
303
304
305
306/// 10^-2 = 1/100
307pub trait PrefixCenti : Sized 
308{ 
309    /// 10^-2 = 1/100
310    const CENTI : Self;
311    /// multiply by 10^-2 = 1/100
312    fn centi(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::CENTI  } 
313}
314impl PrefixCenti for f64   { const CENTI : Self = 1. / 100.; }
315impl PrefixCenti for f32   { const CENTI : Self = 1. / 100.; }
316impl_composite_constant!(PrefixCenti, CENTI);
317
318
319
320/// 10^-3 = 1/1_000
321pub trait PrefixMilli : Sized 
322{ 
323    /// 10^-3 = 1/1_000
324    const MILLI : Self;
325    /// multiply by 10^-3 = 1/1_000
326    fn milli(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::MILLI  } 
327}
328impl PrefixMilli for f64   { const MILLI : Self = 1. / 1_000.; }
329impl PrefixMilli for f32   { const MILLI : Self = 1. / 1_000.; }
330impl_composite_constant!(PrefixMilli, MILLI);
331
332
333/// 10^-6 = 1/1_000_000
334pub trait PrefixMicro : Sized 
335{ 
336    /// 10^-6 = 1/1_000_000
337    const MICRO : Self;
338    /// multiply by 10^-6 = 1/1_000_000
339    fn micro(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::MICRO  } 
340}
341impl PrefixMicro for f64   { const MICRO : Self = 1. / 1_000_000.; }
342impl PrefixMicro for f32   { const MICRO : Self = 1. / 1_000_000.; }
343impl_composite_constant!(PrefixMicro, MICRO);
344
345
346/// 10^-9 = 1/1_000_000_000
347pub trait PrefixNano : Sized 
348{ 
349    /// 10^-9 = 1/1_000_000_000
350    const NANO : Self;
351    /// multiply by 10^-9 = 1/1_000_000_000
352    fn nano(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::NANO  } 
353}
354impl PrefixNano for f64   { const NANO : Self = 1. / 1_000_000_000.; }
355impl PrefixNano for f32   { const NANO : Self = 1. / 1_000_000_000.; }
356impl_composite_constant!(PrefixNano, NANO);
357
358
359/// 10^-12 = 1/1_000_000_000_000
360pub trait PrefixPico : Sized 
361{ 
362    /// 10^-12 = 1/1_000_000_000_000
363    const PICO : Self;
364    /// multiply by 10^-12 = 1/1_000_000_000_000
365    fn pico(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::PICO  } 
366}
367impl PrefixPico for f64   { const PICO : Self = 1. / 1_000_000_000_000.; }
368impl PrefixPico for f32   { const PICO : Self = 1. / 1_000_000_000_000.; }
369impl_composite_constant!(PrefixPico, PICO);
370
371
372/// 10^-15 = 1/1_000_000_000_000_000
373pub trait PrefixFemto : Sized 
374{ 
375    /// 10^-15 = 1/1_000_000_000_000_000
376    const FEMTO : Self;
377    /// multiply by 10^-15 = 1/1_000_000_000_000_000
378    fn femto(self) -> Self where Self : Mul<Self,Output = Self> { self * Self::FEMTO  } 
379}
380impl PrefixFemto for f64   { const FEMTO : Self = 1. / 1_000_000_000_000_000.; }
381impl PrefixFemto for f32   { const FEMTO : Self = 1. / 1_000_000_000_000_000.; }
382impl_composite_constant!(PrefixFemto, FEMTO);
383
384#[cfg(test)]
385mod prefix_test{
386    use crate::*;
387
388    #[test]
389    fn test_prefix() 
390    {
391        assert_eq!(1.kilo(), 1000);
392        assert_eq!([1,2].degree(), [1.degree(),2.degree()]);
393    }
394}