scalars 0.2.0

Minimal numeric traits: Zero, One, Inv, Sqrt, Exp, Trigonometry, Real, Integer
Documentation
#![no_std]

mod float;
mod int;

use core::ops::{Add, Div, Mul, Neg, Rem, Sub};

pub trait Zero {
    fn zero() -> Self;
    fn is_zero(&self) -> bool;
}

pub trait One {
    fn one() -> Self;
    fn is_one(&self) -> bool;
}

pub trait Inv {
    type Output;
    fn inv(self) -> Self::Output;
}

pub trait Sqrt {
    fn sqrt(self) -> Self;
}

pub trait Exp {
    type Output;
    fn exp(self) -> Self::Output;
    fn exp2(self) -> Self::Output;
}

pub trait Trigonometry: Sized {
    fn sin_cos(self) -> [Self; 2];

    fn sin(self) -> Self {
        let [sin, _] = self.sin_cos();
        sin
    }

    fn cos(self) -> Self {
        let [_, cos] = self.sin_cos();
        cos
    }

    fn tan(self) -> Self;
}

pub trait InverseTrigonometry {
    fn asin(self) -> Self;
    fn acos(self) -> Self;
    fn atan(self) -> Self;
    fn atan2(self, other: Self) -> Self;
}

pub trait Clamp: Sized {
    fn min(self, other: Self) -> Self;
    fn max(self, other: Self) -> Self;

    fn clamp(self, lower: Self, upper: Self) -> Self {
        self.max(lower).min(upper)
    }
}

#[cfg(feature = "std")]
pub trait FromStrRadix: Sized {
    type Error;
    fn from_str_radix(source: &str, radix: u32) -> Result<Self, Self::Error>;
}

pub trait Numeric:
    Copy + PartialEq + Add<Output = Self> + Sub<Output = Self> + Mul<Output = Self> + Zero + One
{
}

impl<T> Numeric for T where
    T: Copy + PartialEq + Add<Output = Self> + Sub<Output = Self> + Mul<Output = Self> + Zero + One
{
}

pub trait Integer: Numeric + Eq + Ord + Div<Output = Self> + Rem<Output = Self> {}

impl<T> Integer for T where T: Numeric + Eq + Ord + Div<Output = Self> + Rem<Output = Self> {}

pub trait Real:
    Numeric
    + PartialOrd
    + Div<Output = Self>
    + Neg<Output = Self>
    + Inv<Output = Self>
    + Sqrt
    + Exp<Output = Self>
    + Trigonometry
    + InverseTrigonometry
    + Clamp
{
}

impl<T> Real for T where
    T: Numeric
        + PartialOrd
        + Div<Output = Self>
        + Neg<Output = Self>
        + Inv<Output = Self>
        + Sqrt
        + Exp<Output = Self>
        + Trigonometry
        + InverseTrigonometry
        + Clamp
{
}