hexga_math/other/
prefix.rs1use super::*;
3
4pub trait PrefixPeta : Sized
6{
7 const PETA : Self;
9 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
19pub trait PrefixQuadrillion : Sized
21{
22 const QUADRILLION : Self;
24 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
35pub trait PrefixTera : Sized
37{
38 const TERA : Self;
40 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
50pub trait PrefixTrillion : Sized
52{
53 const TRILLION : Self;
55 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
68pub trait PrefixGiga : Sized
70{
71 const GIGA : Self;
73 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
87pub trait PrefixBillion : Sized
89{
90 const BILLION : Self;
92 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
108pub trait PrefixMega : Sized
110{
111 const MEGA : Self;
113 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
128pub trait PrefixMillion : Sized
130{
131 const MILLION : Self;
133 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
148pub trait PrefixKilo : Sized
150{
151 const KILO : Self;
153 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
169pub trait PrefixThousand : Sized
171{
172 const THOUSAND : Self;
174 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
191pub trait PrefixHecto : Sized
193{
194 const HECTO : Self;
196 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
216pub trait PrefixHundred : Sized
218{
219 const HUNDRED : Self;
221 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
241pub trait PrefixDeca : Sized
243{
244 const DECA : Self;
246 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
267pub trait PrefixDecade : Sized
269{
270 const DECADE : Self;
272 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
292pub trait PrefixDeci : Sized
294{
295 const DECI : Self;
297 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
306pub trait PrefixCenti : Sized
308{
309 const CENTI : Self;
311 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
320pub trait PrefixMilli : Sized
322{
323 const MILLI : Self;
325 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
333pub trait PrefixMicro : Sized
335{
336 const MICRO : Self;
338 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
346pub trait PrefixNano : Sized
348{
349 const NANO : Self;
351 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
359pub trait PrefixPico : Sized
361{
362 const PICO : Self;
364 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
372pub trait PrefixFemto : Sized
374{
375 const FEMTO : Self;
377 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}