LogarithmFunctions

Trait LogarithmFunctions 

Source
pub trait LogarithmFunctions:
    Ln
    + Log2
    + Log10 { }
Expand description

A convenience trait that aggregates the standard logarithm functions.

This trait serves as a shorthand for requiring a type to implement all the fundamental logarithm operations:

  • Ln (natural logarithm)
  • Log10 (base-10 logarithm)
  • Log2 (base-2 logarithm)

It is primarily used as a super-trait for FpScalar to simplify trait bounds and ensure that any scalar type in the library provides a comprehensive set of logarithmic capabilities. By using LogarithmFunctions as a bound, you can write generic functions that utilize any of its constituent trait methods.

§Examples

use num_valid::functions::{LogarithmFunctions, Ln, Log10, Log2};
use std::fmt::Debug;

// A generic function that calculates various logarithms of a number.
// We bound T by FpScalar, which implies LogarithmFunctions.
fn calculate_logs<T>(x: T)
where
    T: LogarithmFunctions + Clone + Debug,
{
    let ln_x = x.clone().ln();
    let log10_x = x.clone().log10();
    let log2_x = x.log2();

    println!("ln(x) = {:?}", ln_x);
    println!("log10(x) = {:?}", log10_x);
    println!("log2(x) = {:?}", log2_x);
}

let value = 100.0f64;
calculate_logs(value);

// Verify the results
assert_eq!(value.ln(), 4.605170185988092);
assert_eq!(value.log10(), 2.0);
assert_eq!(value.log2(), 6.643856189774724);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl LogarithmFunctions for f64

Source§

impl LogarithmFunctions for Complex<f64>

Implementors§