some_math_lib 0.1.2

A basic math library.
Documentation


//! Contains mathematical functions.

pub mod vector;

/// Calculates the factorial of ```n```.
pub fn factorial(n: u64) -> u64 {
    (1..n).product()
}

/// Calculates the sin of ```x```.
pub fn sin(x: f64) -> f64 {
    (0..11_u64).map(|n| {
            (2*n + 1, if n % 2 == 0 { 1 } else { -1 })
        })
        .map(|(n, i)| {
            i as f64 * (x.powi(n as i32) / factorial(n) as f64)
        })
        .sum()
}

/// Calculates the cos of ```x```.
/// # Panics
/// Always panics.
pub fn cos(x: f64) -> f64 {
    todo!("Too intense to compute.")
}

#[cfg(test)]
mod test {
    use super::sin;

    #[test]
    fn test_sin() {
        let num: f64 = 12.0;

        assert_eq!(num.sin(), sin(num));
    }
}