#[repr(transparent)]pub struct Fixed32(pub i32);Expand description
Fixed-point number with 16.16 format (16 integer bits, 16 fractional bits).
Guarantees identical results across ALL platforms per Monniaux (2008): “Floating-point non-determinism is a primary source of divergence in cross-platform replay systems.”
§Examples
use jugar_web::trace::Fixed32;
let a = Fixed32::from_int(5);
let b = Fixed32::from_int(3);
assert_eq!((a + b).to_int(), 8);
assert_eq!((a - b).to_int(), 2);
assert_eq!((a * b).to_int(), 15);
assert_eq!((a / b).to_int(), 1); // Integer divisionTuple Fields§
§0: i32Implementations§
Source§impl Fixed32
impl Fixed32
Sourcepub const fn from_raw(raw: i32) -> Self
pub const fn from_raw(raw: i32) -> Self
Create from raw fixed-point value (internal representation).
Sourcepub fn from_f32(f: f32) -> Self
pub fn from_f32(f: f32) -> Self
Create from f32 (use only for constants, not runtime game logic).
§Warning
This conversion introduces platform-dependent rounding. Only use for initialization from constants; never in game update loops.
Sourcepub fn to_f32(self) -> f32
pub fn to_f32(self) -> f32
Convert to f32 (for rendering only, not game logic).
§Warning
The result may differ slightly across platforms. Only use for rendering; never store or compare these values for game logic.
Sourcepub const fn saturating_add(self, other: Self) -> Self
pub const fn saturating_add(self, other: Self) -> Self
Saturating addition (clamps to MIN/MAX instead of overflowing).
Sourcepub const fn saturating_sub(self, other: Self) -> Self
pub const fn saturating_sub(self, other: Self) -> Self
Saturating subtraction (clamps to MIN/MAX instead of overflowing).
Sourcepub const fn mul(self, other: Self) -> Self
pub const fn mul(self, other: Self) -> Self
Fixed-point multiplication with proper scaling.
Uses i64 intermediate to prevent overflow.
Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Saturating multiplication (clamps instead of overflowing).
Sourcepub const fn div(self, other: Self) -> Self
pub const fn div(self, other: Self) -> Self
Fixed-point division with proper scaling.
Uses i64 intermediate to prevent overflow.
§Panics
Panics if other is zero.
Sourcepub const fn checked_div(self, other: Self) -> Option<Self>
pub const fn checked_div(self, other: Self) -> Option<Self>
Checked division (returns None if divisor is zero).
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Check if negative.
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Check if positive.
Sourcepub const fn lerp(self, other: Self, t: Self) -> Self
pub const fn lerp(self, other: Self, t: Self) -> Self
Linear interpolation between self and other.
t should be between 0.0 and 1.0 (as Fixed32).
Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
Checked multiplication - returns None on overflow (Regehr 2012).
Use this in game logic where overflow indicates a bug that should be caught early in development.
§Examples
use jugar_web::trace::Fixed32;
let a = Fixed32::from_int(100);
let b = Fixed32::from_int(50);
assert_eq!(a.checked_mul(b), Some(Fixed32::from_int(5000)));
// Overflow case
let big = Fixed32::MAX;
assert_eq!(big.checked_mul(Fixed32::from_int(2)), None);Sourcepub const fn strict_mul(self, other: Self) -> Self
pub const fn strict_mul(self, other: Self) -> Self
Strict multiplication - panics on overflow in all builds (Regehr 2012).
Use this in game logic where overflow indicates a bug. This is the safest option for catching bugs early.
§Panics
Panics if the multiplication would overflow.
§Examples
use jugar_web::trace::Fixed32;
let a = Fixed32::from_int(100);
let b = Fixed32::from_int(50);
assert_eq!(a.strict_mul(b), Fixed32::from_int(5000));Sourcepub const fn checked_add(self, other: Self) -> Option<Self>
pub const fn checked_add(self, other: Self) -> Option<Self>
Checked addition - returns None on overflow.
Sourcepub const fn strict_add(self, other: Self) -> Self
pub const fn strict_add(self, other: Self) -> Self
Sourcepub const fn checked_sub(self, other: Self) -> Option<Self>
pub const fn checked_sub(self, other: Self) -> Option<Self>
Checked subtraction - returns None on overflow.
Sourcepub const fn strict_sub(self, other: Self) -> Self
pub const fn strict_sub(self, other: Self) -> Self
Trait Implementations§
Source§impl AddAssign for Fixed32
impl AddAssign for Fixed32
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Fixed32
impl<'de> Deserialize<'de> for Fixed32
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for Fixed32
impl Ord for Fixed32
Source§impl PartialOrd for Fixed32
impl PartialOrd for Fixed32
Source§impl SubAssign for Fixed32
impl SubAssign for Fixed32
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read moreimpl Copy for Fixed32
impl Eq for Fixed32
impl StructuralPartialEq for Fixed32
Auto Trait Implementations§
impl Freeze for Fixed32
impl RefUnwindSafe for Fixed32
impl Send for Fixed32
impl Sync for Fixed32
impl Unpin for Fixed32
impl UnwindSafe for Fixed32
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more