use core::{
fmt::Debug,
ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign},
};
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
use core_maths::CoreFloat;
pub trait Scalar:
Copy
+ Debug
+ PartialEq
+ PartialOrd
+ MinMax
+ Add<Output = Self>
+ AddAssign
+ Sub<Output = Self>
+ SubAssign
+ Mul<Output = Self>
+ MulAssign
+ Div<Output = Self>
+ DivAssign
{
const ZERO: Self;
const ONE: Self;
#[inline]
fn from_scalar<T: Scalar>(value: T) -> Self
where
Self: FromScalar<T>,
{
<Self as FromScalar<T>>::from_scalar(value)
}
#[inline]
fn as_scalar<T: Scalar>(&self) -> T
where
Self: FromScalar<T>,
{
<Self as FromScalar<T>>::as_scalar(self)
}
}
pub trait FloatScalar:
Scalar
+ CoreFloat
+ Neg
+ AbsDiffEq<Epsilon = Self>
+ RelativeEq<Epsilon = Self>
+ UlpsEq<Epsilon = Self>
{
const INFINITY: Self;
const NEG_INFINITY: Self;
const NAN: Self;
fn is_nan(self) -> bool;
fn is_finite(self) -> bool;
fn is_infinite(self) -> bool;
fn is_zero(self) -> bool;
}
pub trait IntScalar: Scalar {}
pub trait MinMax {
fn min(self, other: Self) -> Self;
fn max(self, other: Self) -> Self;
}
pub trait FromScalar<T>: Sized {
fn from_scalar(value: T) -> Self;
fn as_scalar(&self) -> T;
}