1pub mod approx;
2pub use approx::Approx;
3
4pub mod prim;
5pub use prim::Primitive;
6
7pub mod real;
8pub use real::Real;
9
10pub mod traits;
11
12#[cfg(test)]
13mod test;
14
15use num::BigInt;
16
17pub const CMP_MIN_PRECISION: i32 = -128;
18
19pub fn bound_log2(n: i32) -> i32 {
20 ((n.abs() + 1) as f64).log2().ceil() as i32
21}
22
23pub fn scale(n: BigInt, bits: i32) -> BigInt {
24 pub fn shift(n: BigInt, bits: i32) -> BigInt {
25 if bits >= 0 {
26 n << bits
27 } else {
28 n >> -bits
29 }
30 }
31
32 if bits >= 0 {
33 n << bits
34 } else {
35 (shift(n, bits + 1) + BigInt::from(1)) >> 1
36 }
37}