Fixed a lot of the cargo tests. This required Real functions to use libc.
This commit is contained in:
138
src/trig/trig.rs
138
src/trig/trig.rs
@ -11,12 +11,13 @@ pub trait Trig: Real
|
||||
/// Computes the cosine of this angle.
|
||||
///
|
||||
/// ```
|
||||
/// use sigils::Radian;
|
||||
/// use std::f64;
|
||||
/// use sigils::{Constants, Radian, Trig};
|
||||
///
|
||||
/// let x: Radian<f64> = Radian::from(2.0*f64::consts::PI);
|
||||
/// let abs_difference: f64;
|
||||
/// let radians: Radian<f64>;
|
||||
///
|
||||
/// let abs_difference = (x.cos() - 1.0).abs();
|
||||
/// radians = Radian::new(2.0f64 * f64::PI);
|
||||
/// abs_difference = (Trig::cos(radians) - 1.0f64).abs();
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
@ -26,12 +27,13 @@ pub trait Trig: Real
|
||||
/// Computes the sine of this angle.
|
||||
///
|
||||
/// ```
|
||||
/// use sigils::Radian;
|
||||
/// use std::f64;
|
||||
/// use sigils::{Constants, Radian, Trig};
|
||||
///
|
||||
/// let x: Radian<f64> = Radian::from(f64::consts::PI/2.0);
|
||||
/// let abs_difference: f64;
|
||||
/// let radians: Radian<f64>;
|
||||
///
|
||||
/// let abs_difference = (x.sin() - 1.0).abs();
|
||||
/// let radians: Radian<f64> = Radian::new(f64::PI / 2.0f64);
|
||||
/// let abs_difference = (Trig::sin(radians) - 1.0f64).abs();
|
||||
///
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
@ -41,12 +43,13 @@ pub trait Trig: Real
|
||||
/// Computes the tangent of this angle.
|
||||
///
|
||||
/// ```
|
||||
/// use sigils::Radian;
|
||||
/// use std::f64;
|
||||
/// use sigils::{Constants, Radian, Trig};
|
||||
///
|
||||
/// let x: Radian<f64> = Radian::from(f64::consts::PI/4.0);
|
||||
/// let abs_difference: f64;
|
||||
/// let radians: Radian<f64>;
|
||||
///
|
||||
/// let abs_difference = (x.tan() - 1.0).abs();
|
||||
/// radians = Radian::new(f64::PI / 4.0f64);
|
||||
/// abs_difference = (Trig::tan(radians) - 1.0f64).abs();
|
||||
///
|
||||
/// assert!(abs_difference < 1e-14);
|
||||
/// ```
|
||||
@ -58,12 +61,17 @@ pub trait Trig: Real
|
||||
/// [-1, 1].
|
||||
///
|
||||
///```
|
||||
/// use sigils::{Constants, Radian, Real};
|
||||
/// use sigils::{Constants, Radian, Trig};
|
||||
///
|
||||
/// let f: Radian<f64>;
|
||||
/// let angle: f64;
|
||||
/// let radians: Radian<f64>;
|
||||
/// let test: Radian<f64>;
|
||||
///
|
||||
/// f = Radian::from(f64::PI / 4.0f64);
|
||||
/// assert!(((f64::PI / 4.0f64) - *Radian::acos(f.cos())) < 1e-10);
|
||||
/// angle = f64::PI / 4.0f64;
|
||||
/// radians = Radian::new(angle);
|
||||
/// test = Trig::acos(Trig::cos(radians));
|
||||
///
|
||||
/// assert!((angle - *test) < 1e-10);
|
||||
///```
|
||||
fn acos<T>(arg: Self) -> T
|
||||
where T: From<Radian<Self>>;
|
||||
@ -73,12 +81,17 @@ pub trait Trig: Real
|
||||
/// outside the range [-1, 1].
|
||||
///
|
||||
///```
|
||||
/// use sigils::{Constants, Radian, Real};
|
||||
/// use sigils::{Constants, Radian, Trig};
|
||||
///
|
||||
/// let f: Radian<f64>;
|
||||
/// let angle: f64;
|
||||
/// let radians: Radian<f64>;
|
||||
/// let test: Radian<f64>;
|
||||
///
|
||||
/// f = Radian::from(f64::PI / 4.0f64);
|
||||
/// assert!(((f64::PI / 4.0f64) - *Radian::asin(f.sin())) < 1e-10);
|
||||
/// angle = f64::PI / 4.0f64;
|
||||
/// radians = Radian::new(angle);
|
||||
/// test = Trig::asin(Trig::sin(radians));
|
||||
///
|
||||
/// assert!((angle - *test) < 1e-10);
|
||||
///```
|
||||
fn asin<T>(arg: Self) -> T
|
||||
where T: From<Radian<Self>>;
|
||||
@ -87,12 +100,17 @@ pub trait Trig: Real
|
||||
/// range [-pi/2, pi/2];
|
||||
///
|
||||
///```
|
||||
/// use sigils::{Constants, Radian, Real};
|
||||
/// use sigils::{Constants, Radian, Trig};
|
||||
///
|
||||
/// let f: Radian<f64>;
|
||||
/// let angle: f64;
|
||||
/// let radians: Radian<f64>;
|
||||
/// let test: Radian<f64>;
|
||||
///
|
||||
/// f = Radian::from(f64::PI / 4.0f64);
|
||||
/// assert!(((f64::PI / 4.0f64) - *Radian::atan(f.tan())) < 1e-10);
|
||||
/// angle = f64::PI / 4.0f64;
|
||||
/// radians = Radian::new(angle);
|
||||
/// test = Trig::atan(Trig::tan(radians));
|
||||
///
|
||||
/// assert!((angle - *test) < 1e-10);
|
||||
///```
|
||||
fn atan<T>(arg: Self) -> T
|
||||
where T: From<Radian<Self>>;
|
||||
@ -105,76 +123,54 @@ pub trait Trig: Real
|
||||
/// Hyperbolic cosine function.
|
||||
///
|
||||
/// ```
|
||||
/// use sigils::Radian;
|
||||
/// use sigils::Constants;
|
||||
/// use sigils::{Constants, Trig};
|
||||
///
|
||||
/// let e32: f32 = Constants::E;
|
||||
/// let x32: Radian<f32> = Radian::new(1.0f32);
|
||||
/// let f_val32 = x32.cosh();
|
||||
/// let g_val32 = (e32*e32 + 1.0f32)/(2.0f32*e32);
|
||||
/// let abs_difference32 = (f_val32 - g_val32).abs();
|
||||
/// let f_val: f32;
|
||||
/// let g_val: f32;
|
||||
/// let abs_difference: f32;
|
||||
///
|
||||
/// let e64: f64 = Constants::E;
|
||||
/// let x64: Radian<f64> = Radian::new(1.0f64);
|
||||
/// let f_val64 = x64.cosh();
|
||||
/// let g_val64 = (e64*e64 + 1.0f64)/(2.0f64*e64);
|
||||
/// let abs_difference64 = (f_val64 - g_val64).abs();
|
||||
/// f_val = Trig::cosh(1.0f32);
|
||||
/// g_val = (f32::E * f32::E + 1.0f32) / (2.0f32 * f32::E);
|
||||
/// abs_difference = (f_val - g_val).abs();
|
||||
///
|
||||
/// // Solving cosh() at 1 gives this result
|
||||
/// //assert!(abs_difference32 < 1.0e-10);
|
||||
/// assert!(abs_difference64 < 1.0e-10);
|
||||
/// assert!(abs_difference < 1.0e-10);
|
||||
/// ```
|
||||
fn cosh(arg: Self) -> Self;
|
||||
|
||||
/// Hyperbolic sine function.
|
||||
///
|
||||
/// ```
|
||||
/// use sigils::Radian;
|
||||
/// use sigils::Constants;
|
||||
/// use sigils::{Constants, Trig};
|
||||
///
|
||||
/// let e32: f32 = Constants::E;
|
||||
/// let x32: Radian<f32> = Radian::from(1.0f32);
|
||||
/// let f_val: f32;
|
||||
/// let g_val: f32;
|
||||
/// let abs_difference: f32;
|
||||
///
|
||||
/// let f_val32 = x32.sinh();
|
||||
/// let g_val32 = (e32*e32 - 1.0f32)/(2.0f32*e32);
|
||||
/// let abs_difference32 = (f_val32 - g_val32).abs();
|
||||
///
|
||||
/// let e64: f64 = Constants::E;
|
||||
/// let x64: Radian<f64> = Radian::from(1.0f64);
|
||||
///
|
||||
/// let f_val64 = x64.sinh();
|
||||
/// let g_val64 = (e64*e64 - 1.0f64)/(2.0f64*e64);
|
||||
/// let abs_difference64 = (f_val64 - g_val64).abs();
|
||||
/// f_val = Trig::sinh(1.0f32);
|
||||
/// g_val = (f32::E * f32::E - 1.0f32) / (2.0f32 * f32::E);
|
||||
/// abs_difference = (f_val - g_val).abs();
|
||||
///
|
||||
/// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
|
||||
/// //assert!(abs_difference32 < 1e-10);
|
||||
/// assert!(abs_difference64 < 1e-10);
|
||||
/// assert!(abs_difference < 1e-10);
|
||||
/// ```
|
||||
fn sinh(arg: Self) -> Self;
|
||||
|
||||
/// Hyperbolic tangent function.
|
||||
///
|
||||
/// ```
|
||||
/// use sigils::Radian;
|
||||
/// use sigils::Constants;
|
||||
/// use sigils::{Constants, Trig};
|
||||
///
|
||||
/// let e32: f32 = Constants::E;
|
||||
/// let x32: Radian<f32> = Radian::from(1.0f32);
|
||||
///
|
||||
/// let f_val32 = x32.tanh();
|
||||
/// let g_val32 = (1.0f32 - e32.powi(-2i32))/(1.0f32 + e32.powi(-2i32));
|
||||
/// let abs_difference32 = (f_val32 - g_val32).abs();
|
||||
///
|
||||
/// let e64: f64 = Constants::E;
|
||||
/// let x64: Radian<f64> = Radian::from(1.0f64);
|
||||
///
|
||||
/// let f_val64 = x64.tanh();
|
||||
/// let g_val64 = (1.0f64 - e64.powi(-2i32))/(1.0f64 + e64.powi(-2i32));
|
||||
/// let abs_difference64 = (f_val64 - g_val64).abs();
|
||||
/// let f_val: f32;
|
||||
/// let g_val: f32;
|
||||
/// let abs_difference: f32;
|
||||
|
||||
/// f_val = Trig::tanh(1.0f32);
|
||||
/// g_val = (1.0f32 - f32::E.powi(-2i32)) / (1.0f32 + f32::E.powi(-2i32));
|
||||
/// abs_difference = (f_val - g_val).abs();
|
||||
///
|
||||
/// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
|
||||
/// //assert!(abs_difference32 < 1.0e-10);
|
||||
/// assert!(abs_difference64 < 1.0e-10);
|
||||
/// assert!(abs_difference < 1.0e-6);
|
||||
/// ```
|
||||
fn tanh(arg: Self) -> Self;
|
||||
|
||||
|
Reference in New Issue
Block a user