sin_cos_ln_sqrt

Crates.iosin_cos_ln_sqrt
lib.rssin_cos_ln_sqrt
version0.1.1
sourcesrc
created_at2023-01-06 17:58:31.300761
updated_at2023-01-06 18:07:59.853822
descriptionITN crate containing math functions.
homepage
repository
max_upload_size
id752446
size3,921
Max Berliński (GreenSlimeStudios)

documentation

README

use std::f64::consts::E;

pub fn sin(x:f64)->f64{
    let mut result:f64 = 0.0;
    for n in 0..{
        let addition = x.powi(n*2+1) / factorio(n as i128*2+1);
        result += if n % 2 == 0 {addition} else {-addition};
        if addition < 1e-10{
            break;
        }
    }
    result
}
pub fn cos(x:f64)->f64{
    let mut result:f64 = 0.0;
    for n in 0..{
        let addition = x.powi(n*2) / factorio(n as i128*2);
        result += if n % 2 == 0 {addition} else {-addition};
        if addition < 1e-10{
            break;
        }
    }
    result
}
pub fn factorio(x:i128)->f64{
    let mut result:f64 = 1.0;
    for i in 1..=x{
        result *= i as f64;
    }
    result
}
/// ta funkcja jest dokładniejsza od funkcji ln() ale działa tylko w x zakresie 0 > x >= 2 
pub fn ln2(x:f64)->f64{
    if x <= 0.0 || x > 2.0{
        return 0.0;
    }
    let mut result:f64 = 0.0;
    for n in 1..{
        let b:f64 = (-1i32).pow(n+1) as f64;
        let a:f64 = b/n as f64;
        let addition = a*(x-1.0).powi(n as i32);
        result += addition;
        if addition.abs() < 1e-10{
            break;
        }
    }
    result
}
pub fn ln(x:f64)->f64{
    let y:f64=0.000000000001;
    return (x.powf(y)-1.0)/y;
}
/// ta funkcja jest dokładniejsza od funkcji sqrt() ale działa tylko w x zakresie 0 > x >= 2 
pub fn sqrt2(x:f64)->f64{
   return E.powf(ln2(x)/2.0); 
}
pub fn sqrt(x:f64)->f64{
   return E.powf(ln(x)/2.0); 
}
Commit count: 0

cargo fmt