TrigonometricFunctions

Trait TrigonometricFunctions 

Source
pub trait TrigonometricFunctions:
    Sin
    + ASin
    + Cos
    + ACos
    + Tan
    + ATan { }
Expand description

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

This trait serves as a shorthand for requiring a type to implement all the fundamental trigonometric 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 trigonometric capabilities. By using TrigonometricFunctions as a bound, you can write generic functions that utilize any of its constituent trait methods.

§Examples

use num_valid::{FpScalar ,functions::{TrigonometricFunctions, Sin, Cos}};
use std::ops::{Add, Mul};

// A generic function that verifies the identity sin(x)^2 + cos(x)^2 = 1.
// We bound T by FpScalar which implies TrigonometricFunctions, Clone, and arithmetic ops.
fn verify_trig_identity<T>(x: T) -> T
where
    T: TrigonometricFunctions + Clone + Mul<Output = T> + Add<Output = T>,
{
    let sin_x = x.clone().sin();
    let cos_x = x.cos();
    // This works because FpScalar requires the necessary arithmetic traits.
    sin_x.clone() * sin_x + cos_x.clone() * cos_x
}

let angle = 0.5f64;
let identity = verify_trig_identity(angle);

// The result should be very close to 1.0.
assert!((identity - 1.0).abs() < 1e-15);

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 TrigonometricFunctions for f64

Source§

impl TrigonometricFunctions for Complex<f64>

Implementors§