sprinkle const around
This commit is contained in:
parent
ea84e653ac
commit
b48b9bef92
12
src/conv.rs
12
src/conv.rs
|
|
@ -41,23 +41,23 @@ impl From<F8> for f32 {
|
||||||
|
|
||||||
impl F8 {
|
impl F8 {
|
||||||
/// Split self into the mantissa and exponent, as stored.
|
/// Split self into the mantissa and exponent, as stored.
|
||||||
pub(crate) fn split(self) -> (u8, u8) {
|
pub(crate) const fn split(self) -> (u8, u8) {
|
||||||
(self.0 & M_MASK, self.0 >> M_BITS)
|
(self.0 & M_MASK, self.0 >> M_BITS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Split self into integers (m, e) such that `self == m * 2.pow(e)`.
|
/// Split self into integers (m, e) such that `self == m * 2.pow(e)`.
|
||||||
pub(crate) fn split_unbias(self) -> (u8, i8) {
|
pub(crate) const fn split_unbias(self) -> (u8, i8) {
|
||||||
let (m, e) = self.split();
|
let (m, e) = self.split();
|
||||||
(m | M_BIAS, e as i8 - (E_BIAS + M_BITS) as i8)
|
(m | M_BIAS, e as i8 - (E_BIAS + M_BITS) as i8)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn merge(m: u8, e: u8) -> Self {
|
pub(crate) const fn merge(m: u8, e: u8) -> Self {
|
||||||
assert!(m <= M_STORAGE_MAX);
|
assert!(m <= M_STORAGE_MAX);
|
||||||
assert!(e <= E_STORAGE_MAX);
|
assert!(e <= E_STORAGE_MAX);
|
||||||
Self((e << M_BITS) | m)
|
Self((e << M_BITS) | m)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn merge_unbias(in_m: u32, in_e: i32) -> Self {
|
pub(crate) const fn merge_unbias(in_m: u32, in_e: i32) -> Self {
|
||||||
if in_m == 0 {
|
if in_m == 0 {
|
||||||
return Self(0);
|
return Self(0);
|
||||||
}
|
}
|
||||||
|
|
@ -74,11 +74,11 @@ impl F8 {
|
||||||
Self::merge(m as u8 & M_STORAGE_MAX, e as u8)
|
Self::merge(m as u8 & M_STORAGE_MAX, e as u8)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_bits(bits: u8) -> Self {
|
pub const fn from_bits(bits: u8) -> Self {
|
||||||
Self(bits)
|
Self(bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_bits(self) -> u8 {
|
pub const fn to_bits(self) -> u8 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user