#[repr(C)]pub struct FloatValue {
pub number: isize,
}Expand description
Wrapper around an f32 value that is internally casted to an isize, in order to provide hash-ability (to avoid numerical instability).
Fields§
§number: isizeImplementations§
Source§impl FloatValue
impl FloatValue
Sourcepub const fn const_new(value: isize) -> Self
pub const fn const_new(value: isize) -> Self
Same as FloatValue::new(), but only accepts whole numbers,
since using f32 in const fn is not yet stabilized.
Sourcepub const fn const_new_fractional(pre_comma: isize, post_comma: isize) -> Self
pub const fn const_new_fractional(pre_comma: isize, post_comma: isize) -> Self
Creates a FloatValue from a fractional number in const context.
This is needed because f32 operations are not allowed in const fn, but we still want to represent values like 1.5, 0.83, etc.
The function automatically detects the number of decimal places in post_comma
and supports up to 3 decimal places. If more digits are provided, only the first
3 are used (truncation, not rounding).
§Arguments
pre_comma- The integer part (e.g., 1 for 1.5)post_comma- The fractional part as digits (e.g., 5 for 0.5, 52 for 0.52, 523 for 0.523)
§Examples
// 1.5 = const_new_fractional(1, 5)
// 1.52 = const_new_fractional(1, 52)
// 1.523 = const_new_fractional(1, 523)
// 0.83 = const_new_fractional(0, 83)
// 1.17 = const_new_fractional(1, 17)
// 2.123456 -> 2.123 (truncated to 3 decimal places)pub fn new(value: f32) -> Self
pub fn get(&self) -> f32
pub fn interpolate(&self, other: &Self, t: f32) -> Self
Trait Implementations§
Source§impl Clone for FloatValue
impl Clone for FloatValue
Source§fn clone(&self) -> FloatValue
fn clone(&self) -> FloatValue
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FloatValue
impl Debug for FloatValue
Source§impl Default for FloatValue
impl Default for FloatValue
Source§impl Display for FloatValue
impl Display for FloatValue
Source§impl From<f32> for FloatValue
impl From<f32> for FloatValue
Source§impl Hash for FloatValue
impl Hash for FloatValue
Source§impl Ord for FloatValue
impl Ord for FloatValue
Source§fn cmp(&self, other: &FloatValue) -> Ordering
fn cmp(&self, other: &FloatValue) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for FloatValue
impl PartialEq for FloatValue
Source§impl PartialOrd for FloatValue
impl PartialOrd for FloatValue
impl Copy for FloatValue
impl Eq for FloatValue
impl StructuralPartialEq for FloatValue
Auto Trait Implementations§
impl Freeze for FloatValue
impl RefUnwindSafe for FloatValue
impl Send for FloatValue
impl Sync for FloatValue
impl Unpin for FloatValue
impl UnwindSafe for FloatValue
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
Mutably borrows from an owned value. Read more