Trait EstimatedLog2

Source
pub trait EstimatedLog2 {
    // Required method
    fn log2_bounds(&self) -> (f32, f32);

    // Provided method
    fn log2_est(&self) -> f32 { ... }
}
Expand description

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);

Required Methods§

Source

fn log2_bounds(&self) -> (f32, f32)

Estimate the bounds of the binary logarithm.

The result is (lower bound, upper bound) such that lower bound ≤ log2(self) ≤ upper bound. The precision of the bounds must be at least 8 bits (relative error < 2^-8).

With std disabled, the precision is about 13 bits. With std enabled, the precision can be full 24 bits. But the exact precision is not guaranteed and should not be not relied on.

For negative values, the logarithm is calculated based on its absolute value. If the number is zero, then negative infinity will be returned.

Provided Methods§

Source

fn log2_est(&self) -> f32

Estimate the value of the binary logarithm. It’s calculated as the average of log2_bounds by default.

Implementations on Foreign Types§

Source§

impl EstimatedLog2 for f32

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

fn log2_est(&self) -> f32

Source§

impl EstimatedLog2 for f64

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

fn log2_est(&self) -> f32

Source§

impl EstimatedLog2 for i8

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

impl EstimatedLog2 for i16

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

impl EstimatedLog2 for i32

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

impl EstimatedLog2 for i64

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

impl EstimatedLog2 for i128

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

impl EstimatedLog2 for isize

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

impl EstimatedLog2 for u8

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

fn log2_est(&self) -> f32

Source§

impl EstimatedLog2 for u16

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

fn log2_est(&self) -> f32

Source§

impl EstimatedLog2 for u32

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

fn log2_est(&self) -> f32

Source§

impl EstimatedLog2 for u64

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

fn log2_est(&self) -> f32

Source§

impl EstimatedLog2 for u128

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

fn log2_est(&self) -> f32

Source§

impl EstimatedLog2 for usize

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

fn log2_est(&self) -> f32

Source§

impl EstimatedLog2 for IBig

Source§

fn log2_bounds(&self) -> (f32, f32)

Source§

impl EstimatedLog2 for UBig

Source§

fn log2_bounds(&self) -> (f32, f32)

Implementors§

Source§

impl<R: Round, const B: Word> EstimatedLog2 for FBig<R, B>

Source§

impl<const B: Word> EstimatedLog2 for Repr<B>