Debian Codegraph @

src/math/root.rs

raw symbols SCIP
1 use superrust-analyzer cargo dashu-base 0.4.1 math/::{CubicRootrust-analyzer cargo dashu-base 0.4.1 math/CubicRoot#, SquareRootrust-analyzer cargo dashu-base 0.4.1 math/SquareRoot#};
2 use craterust-analyzer cargo dashu-base 0.4.1 crate/::{CubicRootRemrust-analyzer cargo dashu-base 0.4.1 ring/CubicRootRem#, NormalizedRootRemrust-analyzer cargo dashu-base 0.4.1 ring/root/NormalizedRootRem#, SquareRootRemrust-analyzer cargo dashu-base 0.4.1 ring/SquareRootRem#};
3
4 // TODO(next): forward sqrt to f32/f64 if std is enabled and the input is small enough.
5 // Implement after we have a benchmark. See https://github.com/Aatch/ramp/blob/master/src/int.rs#L579.
6
7 impl SquareRootrust-analyzer cargo dashu-base 0.4.1 math/SquareRoot# for u8 {
8 type Outputrust-analyzer cargo dashu-base 0.4.1 math/root/impl#[u8][SquareRoot]Output# = u8;
9
10 #[inline]
11 fn sqrtrust-analyzer cargo dashu-base 0.4.1 math/root/impl#[u8][SquareRoot]sqrt().(&self) -> Selfrust-analyzer cargo dashu-base 0.4.1 math/root/impl#[u8][SquareRoot]::Outputrust-analyzer cargo dashu-base 0.4.1 math/SquareRoot#Output# {
12 self.sqrt_remrust-analyzer cargo dashu-base 0.4.1 ring/root/impl#[u8][SquareRootRem]sqrt_rem().().0
13 }
14 }
15
16 impl CubicRootrust-analyzer cargo dashu-base 0.4.1 math/CubicRoot# for u8 {
17 type Outputrust-analyzer cargo dashu-base 0.4.1 math/root/impl#[u8][CubicRoot]Output# = u8;
18
19 #[inline]
20 fn cbrtrust-analyzer cargo dashu-base 0.4.1 math/root/impl#[u8][CubicRoot]cbrt().(&self) -> Selfrust-analyzer cargo dashu-base 0.4.1 math/root/impl#[u8][CubicRoot]::Outputrust-analyzer cargo dashu-base 0.4.1 math/CubicRoot#Output# {
21 self.cbrt_remrust-analyzer cargo dashu-base 0.4.1 ring/root/impl#[u8][CubicRootRem]cbrt_rem().().0
22 }
23 }
24
25 macro_rules! impl_root_using_rootremrust-analyzer cargo dashu-base 0.4.1 math/root/impl_root_using_rootrem! {
26 ($t:ty, $half:ty) => {
27 impl SquareRoot for $t {
28 type Output = $half;
29
30 #[inline]
31 fn sqrt(&self) -> $half {
32 if *self == 0 {
33 return 0;
34 }
35
36 // normalize the input and call the normalized subroutine
37 let shift = self.leading_zeros() & !1; // make sure shift is divisible by 2
38 let (root, _) = (self << shift).normalized_sqrt_rem();
39 root >> (shift / 2)
40 }
41 }
42
43 impl CubicRoot for $t {
44 type Output = $half;
45
46 #[inline]
47 fn cbrt(&self) -> $half {
48 if *self == 0 {
49 return 0;
50 }
51
52 // normalize the input and call the normalized subroutine
53 let mut shift = self.leading_zeros();
54 shift -= shift % 3; // make sure shift is divisible by 3
55 let (root, _) = (self << shift).normalized_cbrt_rem();
56 root >> (shift / 3)
57 }
58 }
59 };
60 }
61
62 impl_root_using_rootremrust-analyzer cargo dashu-base 0.4.1 math/root/impl_root_using_rootrem!!(u16, u8);
63 impl_root_using_rootremrust-analyzer cargo dashu-base 0.4.1 math/root/impl_root_using_rootrem!!(u32, u16);
64 impl_root_using_rootremrust-analyzer cargo dashu-base 0.4.1 math/root/impl_root_using_rootrem!!(u64, u32);
65 impl_root_using_rootremrust-analyzer cargo dashu-base 0.4.1 math/root/impl_root_using_rootrem!!(u128, u64);