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
//! Trait definitions for math operations
/// Fast estimation of the binary logarithm of a number
///
/// # Panics
///
/// Panics if the number is 0
///
/// # Examples
///
/// ```
/// use dashu_base::EstimatedLog2;
///
/// let lb3 = 1.584962500721156f32;
/// let (lb3_lb, lb3_ub) = 3u8.log2_bounds();
/// assert!(lb3_lb <= lb3 && lb3 <= lb3_ub);
/// assert!((lb3 - lb3_lb) / lb3 < 1. / 256.);
/// assert!((lb3_ub - lb3) / lb3 <= 1. / 256.);
///
/// let lb3_est = 3u8.log2_est();
/// assert!((lb3 - lb3_est).abs() < 1e-3);
/// ```
/// Compute the multiplicative inverse (aka. reciprocal) of the number.
///
/// # Examples
///
/// ```
/// # use dashu_base::Inverse;
/// assert_eq!(0.1234.inv(), 8.103727714748784);
/// assert_eq!(f32::INFINITY.inv(), 0f32);
/// ```
/// Compute the square root of the number.
///
/// The result should be rounded towards zero by default.
///
/// # Examples
///
/// ```
/// # use dashu_base::SquareRoot;
/// assert_eq!(256u32.sqrt(), 16);
/// assert_eq!(257u32.sqrt(), 16);
/// ```
/// Compute the cubic root of the number.
///
/// The result should be rounded towards zero by default.
///
/// # Examples
///
/// ```
/// # use dashu_base::CubicRoot;
/// assert_eq!(216u32.cbrt(), 6);
/// assert_eq!(217u32.cbrt(), 6);
/// ```
pub