diff --git a/src/integer.rs b/src/integer.rs index 4cef070..100db6d 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -1,5 +1,5 @@ //integer units -#[derive(Clone,Copy,Hash,Debug)] +#[derive(Clone,Copy,Hash,PartialEq,PartialOrd,Debug)] pub struct Time(i64); impl Time{ pub const ZERO:Self=Self(0); @@ -228,13 +228,20 @@ pub struct Unit64Mat3{ ///[-1.0,1.0] = [-2^32,2^32] -#[derive(Clone,Copy,Hash)] +#[derive(Clone,Copy,Hash,PartialEq,PartialOrd)] pub struct Planar64(i64); impl Planar64{ + pub const ZERO:Self=Self(0); pub const ONE:Self=Self(2<<32); pub fn int(num:i32)->Self{ Self(Self::ONE.0*num as i64) } + pub fn raw(num:i64)->Self{ + Self(num) + } + pub fn get(&self)->i64{ + self.0 + } pub fn from_ratio(num:i64,den:std::num::NonZeroU64)->Self{ Self(Self::ONE.0*num/den.get() as i64) } @@ -244,6 +251,13 @@ impl Into for Planar64{ self.0 as f32/(2<<32) as f32 } } +impl std::ops::Neg for Planar64{ + type Output=Planar64; + #[inline] + fn neg(self)->Self::Output{ + Planar64(-self.0) + } +} impl std::ops::Add for Planar64{ type Output=Planar64; #[inline] @@ -251,6 +265,13 @@ impl std::ops::Add for Planar64{ Planar64(self.0+rhs.0) } } +impl std::ops::Sub for Planar64{ + type Output=Planar64; + #[inline] + fn sub(self, rhs: Self) -> Self::Output { + Planar64(self.0-rhs.0) + } +} impl std::ops::Mul for Planar64{ type Output=Planar64; #[inline] diff --git a/src/zeroes.rs b/src/zeroes.rs index f220302..5224c4d 100644 --- a/src/zeroes.rs +++ b/src/zeroes.rs @@ -1,26 +1,30 @@ //find roots of polynomials +use crate::integer::Planar64; + #[inline] -pub fn zeroes2(a0:f32,a1:f32,a2:f32) -> Vec{ - if a2==0f32{ +pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64) -> Vec{ + if a2==Planar64::ZERO{ return zeroes1(a0, a1); } - let mut radicand=a1*a1-4f32*a2*a0; - if 0f32 Vec { - if a1==0f32{ +pub fn zeroes1(a0:Planar64,a1:Planar64) -> Vec { + if a1==Planar64::ZERO{ return vec![]; } else { return vec![-a0/a1];