dimensional_quantity 0.1.11

Check units of measure at compile time using generic const expressions
Documentation
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
#![allow(clippy::suspicious_arithmetic_impl)]
//! Dimensional quantity type with generic underlying storage
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
#[cfg(feature = "std")]
pub use num_traits::float::Float;
#[cfg(not(feature = "std"))]
pub use num_traits::float::FloatCore as Float;
use num_traits::{Num, Zero};
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Serialize};

/// Dimensional quantity
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
pub struct QuantityGeneric<
    const L: i64,
    const M: i64,
    const T: i64,
    const I: i64,
    const TH: i64,
    const N: i64,
    const LUM: i64,
    Storage: Num,
>(Storage);

impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num + Zero,
    > Zero for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    Assert<{ TH != 1 }>: IsTrue,
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: Zero,
{
    fn zero() -> Self {
        QuantityGeneric::<L, M, T, I, TH, N, LUM, Storage>(Storage::zero())
    }

    fn is_zero(&self) -> bool {
        self.0.is_zero()
    }

    fn set_zero(&mut self) {
        *self = Zero::zero();
    }
}

impl<
        const L1: i64,
        const M1: i64,
        const T1: i64,
        const I1: i64,
        const TH1: i64,
        const N1: i64,
        const LUM1: i64,
        const L2: i64,
        const M2: i64,
        const T2: i64,
        const I2: i64,
        const TH2: i64,
        const N2: i64,
        const LUM2: i64,
        Storage: Num,
    > Mul<QuantityGeneric<L2, M2, T2, I2, TH2, N2, LUM2, Storage>>
    for QuantityGeneric<L1, M1, T1, I1, TH1, N1, LUM1, Storage>
where
    QuantityGeneric<
        { L1 + L2 },
        { M1 + M2 },
        { T1 + T2 },
        { I1 + I2 },
        { TH1 + TH2 },
        { N1 + N2 },
        { LUM1 + LUM2 },
        Storage,
    >: Sized,
    Storage: Num,
{
    type Output = QuantityGeneric<
        { L1 + L2 },
        { M1 + M2 },
        { T1 + T2 },
        { I1 + I2 },
        { TH1 + TH2 },
        { N1 + N2 },
        { LUM1 + LUM2 },
        Storage,
    >;
    /// Multiply two dimensional quantities
    fn mul(
        self,
        rhs: QuantityGeneric<L2, M2, T2, I2, TH2, N2, LUM2, Storage>,
    ) -> QuantityGeneric<
        { L1 + L2 },
        { M1 + M2 },
        { T1 + T2 },
        { I1 + I2 },
        { TH1 + TH2 },
        { N1 + N2 },
        { LUM1 + LUM2 },
        Storage,
    > {
        let x = self.0;
        let y = rhs.0;
        QuantityGeneric::<
            { L1 + L2 },
            { M1 + M2 },
            { T1 + T2 },
            { I1 + I2 },
            { TH1 + TH2 },
            { N1 + N2 },
            { LUM1 + LUM2 },
            Storage,
        >(x * y)
    }
}

impl<
        const L1: i64,
        const M1: i64,
        const T1: i64,
        const I1: i64,
        const TH1: i64,
        const N1: i64,
        const LUM1: i64,
        const L2: i64,
        const M2: i64,
        const T2: i64,
        const I2: i64,
        const TH2: i64,
        const N2: i64,
        const LUM2: i64,
        Storage: Num,
    > Div<QuantityGeneric<L2, M2, T2, I2, TH2, N2, LUM2, Storage>>
    for QuantityGeneric<L1, M1, T1, I1, TH1, N1, LUM1, Storage>
where
    QuantityGeneric<
        { L1 - L2 },
        { M1 - M2 },
        { T1 - T2 },
        { I1 - I2 },
        { TH1 - TH2 },
        { N1 - N2 },
        { LUM1 - LUM2 },
        Storage,
    >: Sized,
{
    type Output = QuantityGeneric<
        { L1 - L2 },
        { M1 - M2 },
        { T1 - T2 },
        { I1 - I2 },
        { TH1 - TH2 },
        { N1 - N2 },
        { LUM1 - LUM2 },
        Storage,
    >;

    fn div(
        self,
        rhs: QuantityGeneric<L2, M2, T2, I2, TH2, N2, LUM2, Storage>,
    ) -> QuantityGeneric<
        { L1 - L2 },
        { M1 - M2 },
        { T1 - T2 },
        { I1 - I2 },
        { TH1 - TH2 },
        { N1 - N2 },
        { LUM1 - LUM2 },
        Storage,
    > {
        let x = self.0;
        let y = rhs.0;
        QuantityGeneric::<
            { L1 - L2 },
            { M1 - M2 },
            { T1 - T2 },
            { I1 - I2 },
            { TH1 - TH2 },
            { N1 - N2 },
            { LUM1 - LUM2 },
            Storage,
        >(x / y)
    }
}

/// Multiply dimensional quantity by dimensionless number
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > Mul<Storage> for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
{
    type Output = QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>;

    fn mul(self, rhs: Storage) -> QuantityGeneric<L, M, T, I, TH, N, LUM, Storage> {
        let x = self.0;
        QuantityGeneric::<L, M, T, I, TH, N, LUM, Storage>(x * rhs)
    }
}

/// Divide dimensional quantity by dimensionless number
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > Div<Storage> for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
{
    type Output = QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>;

    fn div(self, rhs: Storage) -> QuantityGeneric<L, M, T, I, TH, N, LUM, Storage> {
        let q = self.0;
        QuantityGeneric::<L, M, T, I, TH, N, LUM, Storage>(q / rhs)
    }
}
/// Perform *= operation for a dimensional quantity and a number with Storage type.
/// ```
/// #![feature(generic_const_exprs)]
/// use dimensional_quantity::si::isq::f64::quantities::{Volume};
/// let mut v1 = Volume::new(1.0);
/// v1 *= 10.0;
/// assert_eq!(v1, Volume::new(10.0));
/// ```
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > MulAssign<Storage> for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: MulAssign,
{
    fn mul_assign(&mut self, rhs: Storage) {
        self.0 *= rhs;
    }
}

/// Perform *= operation for a dimensional quantity and a Ratio with same Storage type.
/// ```
/// #![feature(generic_const_exprs)]
/// use dimensional_quantity::si::isq::f64::quantities::{Volume,Ratio};
/// let mut v1 = Volume::new(1.0);
/// let r = Ratio::new(10.0);
/// v1 *= r;
/// assert_eq!(v1, Volume::new(10.0));
/// ```
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > MulAssign<QuantityGeneric<0, 0, 0, 0, 0, 0, 0, Storage>>
    for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: MulAssign,
{
    fn mul_assign(&mut self, rhs: QuantityGeneric<0, 0, 0, 0, 0, 0, 0, Storage>) {
        self.0 *= rhs.0;
    }
}

/// Perform /= operation for a dimensional quantity and a number with Storage type.
/// ```
/// #![feature(generic_const_exprs)]
/// use dimensional_quantity::si::isq::f64::quantities::{Volume};
/// let mut v1 = Volume::new(10.0);
/// v1 /= 10.0;
/// assert_eq!(v1, Volume::new(1.0));
/// ```
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > DivAssign<Storage> for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: DivAssign,
{
    fn div_assign(&mut self, rhs: Storage) {
        self.0 /= rhs;
    }
}

/// Perform /= operation for a dimensional quantity and a Ratio with same Storage type.
/// ```
/// #![feature(generic_const_exprs)]
/// use dimensional_quantity::si::extended::f64::quantities::{Volume,Ratio};
/// let mut v1 = Volume::new(10.0);
/// let r = Ratio::new(10.0);
/// v1 /= r;
/// assert_eq!(v1, Volume::new(1.0));
/// ```
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > DivAssign<QuantityGeneric<0, 0, 0, 0, 0, 0, 0, Storage>>
    for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: DivAssign,
{
    fn div_assign(&mut self, rhs: QuantityGeneric<0, 0, 0, 0, 0, 0, 0, Storage>) {
        self.0 /= rhs.0;
    }
}

/// Addition of dimensional quantities with equal dimension formula
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > Add<QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>>
    for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
{
    type Output = QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>;

    fn add(
        self,
        rhs: QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>,
    ) -> QuantityGeneric<L, M, T, I, TH, N, LUM, Storage> {
        let x = self.0;
        let y = rhs.0;
        QuantityGeneric::<L, M, T, I, TH, N, LUM, Storage>(x + y)
    }
}

/// Implement += operator for dimensional quantities with equal dimension formula
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > AddAssign<QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>>
    for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: AddAssign,
{
    fn add_assign(&mut self, rhs: QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>) {
        self.0 += rhs.0;
    }
}

/// Subtraction of dimensional quantities with equal dimension formula
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > Sub<QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>>
    for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
{
    type Output = QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>;

    fn sub(
        self,
        rhs: QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>,
    ) -> QuantityGeneric<L, M, T, I, TH, N, LUM, Storage> {
        let x = self.0;
        let y = rhs.0;
        QuantityGeneric::<L, M, T, I, TH, N, LUM, Storage>(x - y)
    }
}

/// Implement -= operator for dimensional quantities with equal dimension formula
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > SubAssign<QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>>
    for QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: SubAssign,
{
    fn sub_assign(&mut self, rhs: QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>) {
        self.0 -= rhs.0;
    }
}

impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num + Copy,
    > QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
{
    /// Create a new dimensional quantity with generic storage type.
    /// x -- amount in default (SI) unit
    pub const fn new(x: Storage) -> QuantityGeneric<L, M, T, I, TH, N, LUM, Storage> {
        QuantityGeneric::<L, M, T, I, TH, N, LUM, Storage>(x)
    }
    /// Create a new dimensional quantity with generic storage type from the given value and measurement unit.
    pub fn new_with_unit(
        x: Storage,
        unit: QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>,
    ) -> QuantityGeneric<L, M, T, I, TH, N, LUM, Storage> {
        QuantityGeneric::<L, M, T, I, TH, N, LUM, Storage>(x * unit.0)
    }
    /// Returns dimensional formula of a quantity
    pub const fn dim(&self) -> [i64; 7] {
        [L, M, T, I, TH, N, LUM]
    }

    /// Retrieve the value of the dimensional quantity in the default \[SI\] measurement unit.
    pub const fn get_with_si_unit(&self) -> Storage {
        self.0
    }
    /// Retrieve the value of the dimensional quantity in the given measurement unit.
    pub fn get_with_unit(&self, unit: QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>) -> Storage {
        self.0 / unit.0
    }

    #[cfg(feature = "std")]
    /// Return units-of-measure string  
    /// ```rust
    /// #![feature(generic_const_exprs)]
    /// use dimensional_quantity::si::isq::f64::quantities::LuminousEfficacy;
    /// let l = LuminousEfficacy::new(1.0);
    /// assert_eq!(l.si_uom_str(), "m⁻²⋅kg⁻¹⋅s³⋅cd");
    /// assert_eq!(l.powi::<5>().si_uom_str(),"m⁻¹⁰⋅kg⁻⁵⋅s¹⁵⋅cd⁵");
    /// ```
    pub fn si_uom_str(&self) -> String {
        use crate::format::dim_to_string;
        use std::fmt::Write;

        let mut output = String::new();
        if let Some(dim) = dim_to_string(L) {
            let _ = write!(output, "m{}", dim);
        }
        if let Some(dim) = dim_to_string(M) {
            let _ = write!(output, "kg{}", dim);
        }
        if let Some(dim) = dim_to_string(T) {
            let _ = write!(output, "s{}", dim);
        }
        if let Some(dim) = dim_to_string(I) {
            let _ = write!(output, "A{}", dim);
        }
        if let Some(dim) = dim_to_string(TH) {
            let _ = write!(output, "K{}", dim);
        }
        if let Some(dim) = dim_to_string(N) {
            let _ = write!(output, "mol{}", dim);
        }
        if let Some(dim) = dim_to_string(LUM) {
            let _ = write!(output, "cd{}", dim);
        }
        let mut output = output.chars();
        output.next_back();
        output.collect()
    }

    #[cfg(feature = "std")]
    /// Return units-of-measure formula in TOML  
    /// ```rust
    /// #![feature(generic_const_exprs)]
    /// use dimensional_quantity::si::isq::f64::quantities::LuminousEfficacy;
    /// let l = LuminousEfficacy::new(1.0);
    /// assert_eq!(l.toml_dim_formula(),
    /// "length = -2
    /// mass = -1
    /// time = 3
    /// electric_current = 0
    /// thermodynamic_temperature = 0
    /// amount_of_substance = 0
    /// luminous_intensity = 1");
    /// assert_eq!(l.powi::<5>().toml_dim_formula(),"length = -10
    /// mass = -5
    /// time = 15
    /// electric_current = 0
    /// thermodynamic_temperature = 0
    /// amount_of_substance = 0
    /// luminous_intensity = 5");
    /// ```
    pub fn toml_dim_formula(&self) -> String {
        format!(
            "length = {L}
mass = {M}
time = {T}
electric_current = {I}
thermodynamic_temperature = {TH}
amount_of_substance = {N}
luminous_intensity = {LUM}"
        )
    }
}

impl<Storage: Num + Copy> QuantityGeneric<0, 0, 0, 0, 0, 0, 0, Storage> {
    /// Convert dimensionless Ratio into underlying storage type
    pub fn into_number(&self) -> Storage {
        self.0
    }
}

impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: Float,
{
    /// Raises a dimensional quantity to an integer power.
    pub fn powi<const POWER: i64>(
        &self,
    ) -> QuantityGeneric<
        { L * POWER },
        { M * POWER },
        { T * POWER },
        { I * POWER },
        { TH * POWER },
        { N * POWER },
        { LUM * POWER },
        Storage,
    > {
        QuantityGeneric::<
            { L * POWER },
            { M * POWER },
            { T * POWER },
            { I * POWER },
            { TH * POWER },
            { N * POWER },
            { LUM * POWER },
            Storage,
        >(self.0.powi(POWER as i32))
    }
}

///  Assert for generic const parameters
pub enum Assert<const COND: bool> {}
///  Assert for generic const parameters
pub trait IsTrue {}

impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: Float,
    Assert<{ L % 2 == 0 }>: IsTrue,
    Assert<{ M % 2 == 0 }>: IsTrue,
    Assert<{ T % 2 == 0 }>: IsTrue,
    Assert<{ I % 2 == 0 }>: IsTrue,
    Assert<{ TH % 2 == 0 }>: IsTrue,
    Assert<{ N % 2 == 0 }>: IsTrue,
    Assert<{ LUM % 2 == 0 }>: IsTrue,
{
    /// Square root.
    /// ```
    /// #![feature(generic_const_exprs)]
    /// use dimensional_quantity::si::extended::f64::quantities::{Area, Length};
    /// let a:Area = Area::new(100.0);
    /// let l: Length = a.sqrt();
    ///
    /// assert_eq!(l, Length::new(10.0));
    /// ```
    ///
    /// ```compile_fail
    /// #![feature(generic_const_exprs)]
    /// use dimensional_quantity::si::extended::f64::quantities::{Volume, Length};
    /// let v: Volume = Volume::new(100.0);
    /// let x = v.sqrt();
    ///
    ///
    /// ```
    #[cfg(feature = "std")]
    pub fn sqrt(
        &self,
    ) -> QuantityGeneric<
        { L / 2 },
        { M / 2 },
        { T / 2 },
        { I / 2 },
        { TH / 2 },
        { N / 2 },
        { LUM / 2 },
        Storage,
    > {
        QuantityGeneric::<
            { L / 2 },
            { M / 2 },
            { T / 2 },
            { I / 2 },
            { TH / 2 },
            { N / 2 },
            { LUM / 2 },
            Storage,
        >(self.0.sqrt())
    }
}

impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
        Storage: Num,
    > QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>
where
    QuantityGeneric<L, M, T, I, TH, N, LUM, Storage>: Sized,
    Storage: Float,
    Assert<{ L % 3 == 0 }>: IsTrue,
    Assert<{ M % 3 == 0 }>: IsTrue,
    Assert<{ T % 3 == 0 }>: IsTrue,
    Assert<{ I % 3 == 0 }>: IsTrue,
    Assert<{ TH % 3 == 0 }>: IsTrue,
    Assert<{ N % 3 == 0 }>: IsTrue,
    Assert<{ LUM % 3 == 0 }>: IsTrue,
{
    /// Cubic root.
    /// ```
    /// #![feature(generic_const_exprs)]
    /// use dimensional_quantity::si::extended::f64::quantities::{Volume, Length};
    /// let v: Volume = Volume::new(1000.0);
    /// let l: Length = v.cbrt();
    ///
    /// assert_eq!(l, Length::new(10.0));
    /// ```
    ///
    /// ```compile_fail
    /// #![feature(generic_const_exprs)]
    /// use dimensional_quantity::si::extended::f64::quantities::{Area, Length};
    /// let a: Area = Area::new(100.0);
    /// let x = a.cbrt();
    ///
    ///
    /// ```
    #[cfg(feature = "std")]
    pub fn cbrt(
        &self,
    ) -> QuantityGeneric<
        { L / 3 },
        { M / 3 },
        { T / 3 },
        { I / 3 },
        { TH / 3 },
        { N / 3 },
        { LUM / 3 },
        Storage,
    > {
        QuantityGeneric::<
            { L / 3 },
            { M / 3 },
            { T / 3 },
            { I / 3 },
            { TH / 3 },
            { N / 3 },
            { LUM / 3 },
            Storage,
        >(self.0.cbrt())
    }
}

/// Divide f64 by QuantityGeneric with f64 Storage type
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
    > Div<QuantityGeneric<L, M, T, I, TH, N, LUM, f64>> for f64
where
    QuantityGeneric<{ -L }, { -M }, { -T }, { -I }, { -TH }, { -N }, { -LUM }, f64>: Sized,
{
    type Output = QuantityGeneric<{ -L }, { -M }, { -T }, { -I }, { -TH }, { -N }, { -LUM }, f64>;

    fn div(
        self,
        rhs: QuantityGeneric<L, M, T, I, TH, N, LUM, f64>,
    ) -> QuantityGeneric<{ -L }, { -M }, { -T }, { -I }, { -TH }, { -N }, { -LUM }, f64> {
        let rhs = rhs.0;
        QuantityGeneric::<{ -L }, { -M }, { -T }, { -I }, { -TH }, { -N }, { -LUM }, f64>(
            self / rhs,
        )
    }
}

/// Multiply f64 by QuantityGeneric with f64 Storage type
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
    > Mul<QuantityGeneric<L, M, T, I, TH, N, LUM, f64>> for f64
{
    type Output = QuantityGeneric<L, M, T, I, TH, N, LUM, f64>;

    fn mul(
        self,
        rhs: QuantityGeneric<L, M, T, I, TH, N, LUM, f64>,
    ) -> QuantityGeneric<L, M, T, I, TH, N, LUM, f64> {
        let x = rhs.0;
        QuantityGeneric::<L, M, T, I, TH, N, LUM, f64>(self * x)
    }
}

/// Divide f32 by QuantityGeneric with f32 storage type
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
    > Div<QuantityGeneric<L, M, T, I, TH, N, LUM, f32>> for f32
where
    QuantityGeneric<{ -L }, { -M }, { -T }, { -I }, { -TH }, { -N }, { -LUM }, f32>: Sized,
{
    type Output = QuantityGeneric<{ -L }, { -M }, { -T }, { -I }, { -TH }, { -N }, { -LUM }, f32>;

    fn div(
        self,
        rhs: QuantityGeneric<L, M, T, I, TH, N, LUM, f32>,
    ) -> QuantityGeneric<{ -L }, { -M }, { -T }, { -I }, { -TH }, { -N }, { -LUM }, f32> {
        let rhs = rhs.0;
        QuantityGeneric::<{ -L }, { -M }, { -T }, { -I }, { -TH }, { -N }, { -LUM }, f32>(
            self / rhs,
        )
    }
}

/// Multiply f32 by QuantityGeneric with f32 storage type
impl<
        const L: i64,
        const M: i64,
        const T: i64,
        const I: i64,
        const TH: i64,
        const N: i64,
        const LUM: i64,
    > Mul<QuantityGeneric<L, M, T, I, TH, N, LUM, f32>> for f32
{
    type Output = QuantityGeneric<L, M, T, I, TH, N, LUM, f32>;

    fn mul(
        self,
        rhs: QuantityGeneric<L, M, T, I, TH, N, LUM, f32>,
    ) -> QuantityGeneric<L, M, T, I, TH, N, LUM, f32> {
        let x = rhs.0;
        QuantityGeneric::<L, M, T, I, TH, N, LUM, f32>(self * x)
    }
}
impl<Storage: Num> From<Storage> for QuantityGeneric<0, 0, 0, 0, 0, 0, 0, Storage> {
    fn from(value: Storage) -> Self {
        QuantityGeneric::<0, 0, 0, 0, 0, 0, 0, Storage>(value)
    }
}
impl From<QuantityGeneric<0, 0, 0, 0, 0, 0, 0, f64>> for f64 {
    fn from(value: QuantityGeneric<0, 0, 0, 0, 0, 0, 0, f64>) -> Self {
        value.0
    }
}

impl From<QuantityGeneric<0, 0, 0, 0, 0, 0, 0, f32>> for f32 {
    fn from(value: QuantityGeneric<0, 0, 0, 0, 0, 0, 0, f32>) -> Self {
        value.0
    }
}