From 8a13307d98da8611de2cccd239f56eca49dde715 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 27 Aug 2024 13:51:20 -0700 Subject: [PATCH] the replacement of all time --- src/integer.rs | 648 +------------------------------------------------ 1 file changed, 4 insertions(+), 644 deletions(-) diff --git a/src/integer.rs b/src/integer.rs index 377a097..4839d17 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -427,650 +427,10 @@ impl TryFrom<[f32;3]> for Unit32Vec3{ } */ -///[-1.0,1.0] = [-2^32,2^32] -#[derive(Clone,Copy,Debug,Hash,Eq,Ord,PartialEq,PartialOrd)] -pub struct Planar64(i64); -impl Planar64{ - pub const ZERO:Self=Self(0); - pub const ONE:Self=Self(1<<32); - pub const MAX:Self=Self(i64::MAX); - pub const MIN:Self=Self(i64::MIN); - #[inline] - pub const fn int(num:i32)->Self{ - Self(Self::ONE.0*num as i64) - } - #[inline] - pub const fn raw(num:i64)->Self{ - Self(num) - } - #[inline] - pub const fn get(&self)->i64{ - self.0 - } - #[inline] - pub const fn abs(self)->Self{ - Self(self.0.abs()) - } - #[inline] - pub fn sqrt(&self)->Self{ - Planar64(unsafe{(((self.0 as i128)<<32) as f64).sqrt().to_int_unchecked()}) - } - #[inline] - pub const fn signum_i64(&self)->i64{ - ((self.0&(1<<63)!=0) as i64)*2-1 - } -} -const PLANAR64_ONE_FLOAT32:f32=(1u64<<32) as f32; -const PLANAR64_CONVERT_TO_FLOAT32:f32=1.0/PLANAR64_ONE_FLOAT32; -const PLANAR64_ONE_FLOAT64:f64=(1u64<<32) as f64; -impl Into for Planar64{ - #[inline] - fn into(self)->f32{ - self.0 as f32*PLANAR64_CONVERT_TO_FLOAT32 - } -} -impl From for Planar64{ - #[inline] - fn from(ratio:Ratio64)->Self{ - Self((((ratio.num as i128)<<32)/(ratio.den as i128)) as i64) - } -} -#[derive(Debug)] -pub enum Planar64TryFromFloatError{ - Nan, - Infinite, - Subnormal, - HighlyNegativeExponent, - HighlyPositiveExponent, -} -impl TryFrom for Planar64{ - type Error=Planar64TryFromFloatError; - #[inline] - fn try_from(value:f32)->Result{ - match value.classify(){ - std::num::FpCategory::Nan=>Err(Self::Error::Nan), - std::num::FpCategory::Infinite=>Err(Self::Error::Infinite), - std::num::FpCategory::Zero=>Ok(Self::ZERO), - std::num::FpCategory::Subnormal - |std::num::FpCategory::Normal=>{ - let planar=value*PLANAR64_ONE_FLOAT32; - if planar<(i64::MIN as f32)||(i64::MAX as f32) for Planar64{ - type Error=Planar64TryFromFloatError; - #[inline] - fn try_from(value:f64)->Result{ - match value.classify(){ - std::num::FpCategory::Nan=>Err(Self::Error::Nan), - std::num::FpCategory::Infinite=>Err(Self::Error::Infinite), - std::num::FpCategory::Zero=>Ok(Self::ZERO), - std::num::FpCategory::Subnormal - |std::num::FpCategory::Normal=>{ - let planar=value*PLANAR64_ONE_FLOAT64; - if planar<(i64::MIN as f64)||(i64::MAX as f64))->std::fmt::Result{ - write!(f,"{:.3}", - Into::::into(*self), - ) - } -} -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] - fn add(self, rhs: Self) -> Self::Output { - Planar64(self.0+rhs.0) - } -} -impl std::ops::AddAssign for Planar64{ - #[inline] - fn add_assign(&mut self,rhs:Self){ - *self=*self+rhs; - } -} -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] - fn mul(self, rhs: i64) -> Self::Output { - Planar64(self.0*rhs) - } -} -impl std::ops::Mul for Planar64{ - type Output=Planar64; - #[inline] - fn mul(self, rhs: Self) -> Self::Output { - Planar64(((self.0 as i128*rhs.0 as i128)>>32) as i64) - } -} -impl std::ops::Mul