rutil 0.2.0

A library containing utilities for creating programs in rust.
Documentation
/// Trigonometric operations.
pub trait TrigonometricOps: Sized {
    /// Calculates the length of the hypotenuse of a right-angle triangle given
    /// legs of length `x` and `y`.
    fn hypot(self, other: Self) -> Self;

    /// Computes the sine of a number (in radians).
    fn sin(self) -> Self;

    /// Computes the cosine of a number (in radians).
    fn cos(self) -> Self;

    /// Computes the tangent of a number (in radians).
    fn tan(self) -> Self;

    /// Computes the arcsine of a number. Return value is in radians in
    /// the range [-pi/2, pi/2] or NaN if the number is outside the range
    /// [-1, 1].
    fn asin(self) -> Self;

    /// Computes the arccosine of a number. Return value is in radians in
    /// the range [0, pi] or NaN if the number is outside the range
    /// [-1, 1].
    fn acos(self) -> Self;

    /// Computes the arctangent of a number. Return value is in radians in the
    /// range [-pi/2, pi/2];
    fn atan(self) -> Self;

    /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
    ///
    /// * `x = 0`, `y = 0`: `0`
    /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
    /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
    /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
    fn atan2(self, other: Self) -> Self;

    /// Simultaneously computes the sine and cosine of the number, `x`. Returns
    /// `(sin(x), cos(x))`.
    fn sin_cos(self) -> (Self, Self);
}

/// Implements [`TrigonometricOps`].
macro_rules! impl_trigonometric {
    ($($t:ty),*) => {
        $(impl TrigonometricOps for $t {
            #[inline] fn hypot(self, other: Self) -> Self { self.hypot(other) }
            #[inline] fn sin(self) -> Self { self.sin() }
            #[inline] fn cos(self) -> Self { self.cos() }
            #[inline] fn tan(self) -> Self { self.tan() }
            #[inline] fn asin(self) -> Self { self.asin() }
            #[inline] fn acos(self) -> Self { self.acos() }
            #[inline] fn atan(self) -> Self { self.atan() }
            #[inline] fn atan2(self, other: Self) -> Self { self.atan2(other) }
            #[inline] fn sin_cos(self) -> (Self, Self) { self.sin_cos() }
        })*
    };
}

impl_trigonometric!(f32, f64);