Skip to main content

HyperbolicFunctions

Trait HyperbolicFunctions 

Source
pub trait HyperbolicFunctions:
    SinH
    + ASinH
    + CosH
    + ACosH
    + TanH
    + ATanH { }
Expand description

A convenience trait that aggregates the standard hyperbolic functions and their inverses.

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

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 hyperbolic capabilities. By using HyperbolicFunctions as a bound, you can write generic functions that utilize any of its constituent trait methods.

§Examples

use num_valid::functions::{HyperbolicFunctions, Abs};
use std::ops::{Mul, Sub};

// A generic function that verifies the identity cosh(x)^2 - sinh(x)^2 = 1.
// We bound T by HyperbolicFunctions, Clone, and arithmetic ops.
fn verify_hyperbolic_identity<T>(x: T) -> T
where
    T: HyperbolicFunctions + Clone + Sub<Output = T> + Mul<Output = T>,
{
    let cosh_x = x.clone().cosh();
    let sinh_x = x.sinh();
    // This works because FpScalar requires the necessary arithmetic traits.
    cosh_x.clone() * cosh_x - sinh_x.clone() * sinh_x
}

let value = 0.5f64;
let identity = verify_hyperbolic_identity(value);

// The result should be very close to 1.0.
// We use the Abs trait for comparison.
assert!((identity - 1.0).abs() < 1e-12);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl HyperbolicFunctions for Complex<f64>

Source§

impl HyperbolicFunctions for f64

Implementors§