pub struct Confidence(/* private fields */);Expand description
A confidence value in [0.0, 1.0], stored as 16-bit fixed-point.
The representation gives a resolution of roughly 1.53e-5 per step
and is bit-identical across architectures — no IEEE 754 divergence
between CPUs. Per docs/concepts/ir-canonical-form.md § 3.1:
stored_u16 = round(confidence * 65535.0)
confidence = stored_u16 / 65535.0§Examples
use mimir_core::Confidence;
let c = Confidence::try_from_f32(0.95).unwrap();
assert!((c.as_f32() - 0.95).abs() < 1e-4);
assert_eq!(c.as_u16(), 62_258);Implementations§
Source§impl Confidence
impl Confidence
Sourcepub fn try_from_f32(value: f32) -> Result<Self, ConfidenceError>
pub fn try_from_f32(value: f32) -> Result<Self, ConfidenceError>
Construct a Confidence from an f32 in [0.0, 1.0].
Rounds half-to-even.
§Errors
ConfidenceError::OutOfRangeifvalue < 0.0orvalue > 1.0.ConfidenceError::NotANumberifvalueis NaN.
Subnormal values and negative zero are treated as 0.0.
§Examples
use mimir_core::{Confidence, ConfidenceError};
assert!(Confidence::try_from_f32(0.5).is_ok());
assert_eq!(
Confidence::try_from_f32(1.1),
Err(ConfidenceError::OutOfRange(1.1)),
);
assert_eq!(
Confidence::try_from_f32(f32::NAN),
Err(ConfidenceError::NotANumber),
);Sourcepub const fn from_u16(raw: u16) -> Self
pub const fn from_u16(raw: u16) -> Self
Construct a Confidence from its raw u16 fixed-point encoding.
Trait Implementations§
Source§impl Clone for Confidence
impl Clone for Confidence
Source§fn clone(&self) -> Confidence
fn clone(&self) -> Confidence
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 Confidence
impl Debug for Confidence
Source§impl Display for Confidence
impl Display for Confidence
Source§impl Hash for Confidence
impl Hash for Confidence
Source§impl Ord for Confidence
impl Ord for Confidence
Source§fn cmp(&self, other: &Confidence) -> Ordering
fn cmp(&self, other: &Confidence) -> 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 Confidence
impl PartialEq for Confidence
Source§impl PartialOrd for Confidence
impl PartialOrd for Confidence
impl Copy for Confidence
impl Eq for Confidence
impl StructuralPartialEq for Confidence
Auto Trait Implementations§
impl Freeze for Confidence
impl RefUnwindSafe for Confidence
impl Send for Confidence
impl Sync for Confidence
impl Unpin for Confidence
impl UnsafeUnpin for Confidence
impl UnwindSafe for Confidence
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
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
Compare self to
key and return true if they are equal.