integer: tweak Time
This commit is contained in:
parent
5c059ed17d
commit
aaad5d5c22
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -92,6 +92,7 @@ dependencies = [
|
|||||||
"glam",
|
"glam",
|
||||||
"id",
|
"id",
|
||||||
"linear_ops",
|
"linear_ops",
|
||||||
|
"ratio_ops",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -14,5 +14,6 @@ arrayvec = "0.7.4"
|
|||||||
bitflags = "2.6.0"
|
bitflags = "2.6.0"
|
||||||
fixed_wide = { path = "../fixed_wide_vectors/fixed_wide", features = ["deferred-division","zeroes","wide-mul"] }
|
fixed_wide = { path = "../fixed_wide_vectors/fixed_wide", features = ["deferred-division","zeroes","wide-mul"] }
|
||||||
linear_ops = { path = "../fixed_wide_vectors/linear_ops", features = ["deferred-division","named-fields"] }
|
linear_ops = { path = "../fixed_wide_vectors/linear_ops", features = ["deferred-division","named-fields"] }
|
||||||
|
ratio_ops = { path = "../fixed_wide_vectors/ratio_ops" }
|
||||||
glam = "0.28.0"
|
glam = "0.28.0"
|
||||||
id = { version = "0.1.0", registry = "strafesnet" }
|
id = { version = "0.1.0", registry = "strafesnet" }
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
use fixed_wide::fixed::Fixed;
|
||||||
|
use ratio_ops::ratio::Ratio;
|
||||||
|
|
||||||
//integer units
|
//integer units
|
||||||
#[derive(Clone,Copy,Hash,Eq,PartialEq,PartialOrd,Debug)]
|
#[derive(Clone,Copy,Hash,Eq,PartialEq,PartialOrd,Debug)]
|
||||||
pub struct Time(i64);
|
pub struct Time(i64);
|
||||||
@ -63,25 +66,25 @@ impl std::ops::Neg for Time{
|
|||||||
Time(-self.0)
|
Time(-self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::ops::Add<Time> for Time{
|
macro_rules! impl_time_additive_operator {
|
||||||
type Output=Time;
|
($trait:ty, $method:ident) => {
|
||||||
#[inline]
|
impl $trait for Time{
|
||||||
fn add(self,rhs:Self)->Self::Output {
|
type Output=Time;
|
||||||
Time(self.0+rhs.0)
|
#[inline]
|
||||||
}
|
fn $method(self,rhs:Self)->Self::Output {
|
||||||
|
Time(self.0.$method(rhs.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
impl std::ops::Sub<Time> for Time{
|
impl_time_additive_operator!(core::ops::Add,add);
|
||||||
type Output=Time;
|
impl_time_additive_operator!(core::ops::Sub,sub);
|
||||||
|
impl_time_additive_operator!(core::ops::Rem,rem);
|
||||||
|
impl std::ops::Mul for Time{
|
||||||
|
type Output=Ratio<fixed_wide::fixed::Fixed<2,64>,fixed_wide::fixed::Fixed<2,64>>;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(self,rhs:Self)->Self::Output {
|
fn mul(self,rhs:Self)->Self::Output{
|
||||||
Time(self.0-rhs.0)
|
Ratio::new(Fixed::raw(self.0)*Fixed::raw(rhs.0),Fixed::raw_digit(1_000_000_000i64.pow(2)))
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::ops::Mul<Time> for Time{
|
|
||||||
type Output=Time;
|
|
||||||
#[inline]
|
|
||||||
fn mul(self,rhs:Time)->Self::Output{
|
|
||||||
Self((((self.0 as i128)*(rhs.0 as i128))/1_000_000_000) as i64)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::ops::Div<i64> for Time{
|
impl std::ops::Div<i64> for Time{
|
||||||
@ -92,6 +95,13 @@ impl std::ops::Div<i64> for Time{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl core::ops::Mul<Time> for Planar64{
|
||||||
|
type Output=Ratio<Fixed<2,64>,Planar64>;
|
||||||
|
fn mul(self,rhs:Time)->Self::Output{
|
||||||
|
Ratio::new(self*Fixed::raw(rhs.0),Planar64::raw(1_000_000_000))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
const fn gcd(mut a:u64,mut b:u64)->u64{
|
const fn gcd(mut a:u64,mut b:u64)->u64{
|
||||||
while b!=0{
|
while b!=0{
|
||||||
|
Loading…
Reference in New Issue
Block a user