Add public API and docs #1

Open
noteuclid wants to merge 8 commits from api into master
Showing only changes of commit 3056efc1a2 - Show all commits

View File

@ -73,6 +73,33 @@ impl F8 {
}
Self::merge(m as u8 & M_STORAGE_MAX, e as u8)
}
pub fn from_bits(bits: u8) -> Self {
Self(bits)
}
pub fn to_bits(self) -> u8 {
self.0
}
/// Calculate `base * 2.pow(scale)`, preserving as much precision as possible.
pub fn ldexp(base: u32, scale: i32) -> Self {
Self::merge_unbias(base, scale)
}
/// Split `self` into `(base, scale)` such that `self = base * 2.pow(scale)`.
///
/// ```
/// # use f8::F8;
/// # let val = F8::from_bits(42);
/// let (base, scale) = val.frexp();
/// let val2 = F8::ldexp(base, scale);
/// assert_eq!(val, val2);
/// ```
pub fn frexp(self) -> (u32, i32) {
let (base, scale) = self.split_unbias();
(base.into(), scale.into())
}
}
#[cfg(test)]