Compare commits
1 Commits
absrel
...
truncate-a
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e83366386 |
@@ -1,6 +0,0 @@
|
||||
[package]
|
||||
name = "absrel"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -1,4 +0,0 @@
|
||||
/// This type represents an absolute value, such as a coordinate for a world position.
|
||||
/// This is called a euclidean point in Geometric Algebra.
|
||||
/// The most appropriate type here is a fixed-point value.
|
||||
pub struct Absolute<T>(T);
|
||||
@@ -1,2 +0,0 @@
|
||||
pub mod abs;
|
||||
pub mod rel;
|
||||
@@ -1,8 +0,0 @@
|
||||
/// This type represents the difference between two absolute values.
|
||||
/// This is called an ideal point in Geometric Algebra.
|
||||
/// After you get your time delta or position delta,
|
||||
/// implement your number-crunching logic using this type.
|
||||
/// Once the calculation is complete, it can be added to an absolute value
|
||||
/// with the effect of offsetting the value to a new absolute value.
|
||||
/// The most appropriate type here is a floating point value.
|
||||
pub struct Relative<T>(T);
|
||||
@@ -585,6 +585,9 @@ macro_rules! impl_fix_rhs_lt_lhs_not_const_generic{
|
||||
paste::item!{
|
||||
#[inline]
|
||||
pub fn [<fix_ $rhs>](self)->Fixed<$rhs,{$rhs*32}>{
|
||||
let max=bnum::cast::As::as_::<BInt::<$lhs>>(BInt::<$rhs>::MAX).shl(($lhs-$rhs)*32);
|
||||
let min=bnum::cast::As::as_::<BInt::<$lhs>>(BInt::<$rhs>::MIN).shl(($lhs-$rhs)*32);
|
||||
assert!(min<self.bits&&self.bits<max,"Truncation detected");
|
||||
Fixed::from_bits(bnum::cast::As::as_::<BInt::<$rhs>>(self.bits.shr(($lhs-$rhs)*32)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user