pub struct FloatValue { /* private fields */ }Expand description
Wrapper around an f32 value that is internally casted to an isize, in order to provide hash-ability (to avoid numerical instability).
Implementations§
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.
Uses isize arithmetic to avoid floating-point in const context.
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 uses integer arithmetic to represent fractional values like 1.5, 0.83, etc. in const context without relying on f32 operations.
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
Sourcepub const fn number(&self) -> isize
pub const fn number(&self) -> isize
Returns the raw encoded isize (the f32 value scaled by
FP_PRECISION_MULTIPLIER). Exposed so external callers can
round-trip the value through the compact-cache encoding without
re-multiplying through 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
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more