pub struct HeadByte(/* private fields */);Expand description
The Head Byte itself, containing information about the sign, presence of the exponent and the number of coefficients.
Follows the newtype pattern, meaning that it can be unwrapped into the inner byte.
Implementations§
Source§impl HeadByte
impl HeadByte
Sourcepub const ABS_MASK: u8 = 127u8
pub const ABS_MASK: u8 = 127u8
The mask used for retreiving the absolute value of the number.
Use abs or bitwise-AND (&) this with the Head Byte to retreive the absolute value.
Sourcepub const HAS_EXPONENT_MASK: u8 = 64u8
pub const HAS_EXPONENT_MASK: u8 = 64u8
The exponent presence bit mask.
Use has_exponent to easily retreive this.
Sourcepub const NUM_COEFFICIENTS_MASK: u8 = 63u8
pub const NUM_COEFFICIENTS_MASK: u8 = 63u8
Mask for the number of coefficients.
Use num_coefficients to easily retreive this.
Sourcepub const INFINITY: Self
pub const INFINITY: Self
The ∞ (positive infinity) value for the Head Byte.
No following exponent or coefficients are allowed in this case, despite the exponent bit being set.
Sourcepub const NEG_INFINITY: Self
pub const NEG_INFINITY: Self
The -∞ (negative infinity) value for the Head Byte.
No following exponent or coefficients are allowed in this case, despite the exponent bit being set.
Sourcepub const ZERO: Self
pub const ZERO: Self
The zero value. There’s no distinction between positive and negative zero.
No following exponent or coefficients are allowed.
Sourcepub const NAN: Self
pub const NAN: Self
The NaN (Not-a-Number) value. There’s no distinction between negative/positive NaN or signalling/quiet NaN. (This implementation always generates quiet NaN.)
NaN values aren’t equal to themselves, just like in IEEE 754. To check for NaN values, use either is_nan or, if you’re using the try_nan feature (which currently only works on Nightly), the Try trait, which returns an error if the value is NaN.
No following exponent or coefficients are allowed.
Sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Calculates the absolute value from the number whose Head Byte is self.
Since the Head Byte stores the sign of the entire number, it’s enough to just perform bitwise AND with the ABS_MASK, which in turn is the bitwise NOT of the sign mask.
Sourcepub const fn exponent_bit(self) -> bool
pub const fn exponent_bit(self) -> bool
Checks whether the HAS_EXPONENT bit of the Head Byte is set, meaning either infinity or the presence of an actual exponent.
For a version which also checks for the infinity special case, see has_exponent.
Sourcepub fn with_exponent_bit(self, op: bool) -> Self
pub fn with_exponent_bit(self, op: bool) -> Self
Constructs a Head Byte which has the same sign flag and number of following bytes expected as the one specified but also sets the exponent presence bit to a new value.
The in-place counterpart is set_exponent_bit.
Sourcepub fn set_exponent_bit(&mut self, op: bool)
pub fn set_exponent_bit(&mut self, op: bool)
Sets the exponent presence bit in the Head Byte. If the number of expected bytes which follow the number is zero, setting it to true produces the infinity special-case Head Byte.
For a version of this funciton which returns the result instead of performing the operation in-place, see with_exponent_bit.
Sourcepub fn is_infinite(self) -> bool
pub fn is_infinite(self) -> bool
Checks whether the Head Byte describes either positive or negative infinity.
This is mostly uesd in has_exponent to check for the infinity special case.
Sourcepub fn has_exponent(self) -> bool
pub fn has_exponent(self) -> bool
Checks whether the Head Byte is supposed to be followed by an exponent byte.
This includes the check for the special infinity value. For a version which does not check for infinity and thus plays more nicely with branch prediction, see exponent_bit_set.
Sourcepub const fn num_bytes(self) -> u8
pub const fn num_bytes(self) -> u8
Fetches the number of bytes in the number which are supposed to follow the Head Byte.
This is equal to the number of following coefficients if there is no exponent or that number plus one if there is an exponent.
Sourcepub fn num_coefficients(self) -> u8
pub fn num_coefficients(self) -> u8
Fetches the number of following coefficients.
This is equal to the number of following bytes if there is no exponent or that number minus one if there is an exponent.
Sourcepub fn with_num_bytes(self, op: u8) -> Self
pub fn with_num_bytes(self, op: u8) -> Self
Constructs a Head Byte which has the same sign and exponent flags as the one specified but also sets the number of following bytes expected to a new value.
Panics if the number cannot fit into the Head Byte’s byte count field.
The in-place counterpart is with_num_bytes.
Sourcepub fn set_num_bytes(&mut self, op: u8)
pub fn set_num_bytes(&mut self, op: u8)
Sets the number of bytes which are supposed to follow the Head Byte.
Panics if the number cannot fit into the Head Byte’s byte count field.
For a version of this funciton which returns the result instead of performing the operation in-place, see with_num_bytes.
Sourcepub fn with_num_coefficients(self, op: u8) -> Self
pub fn with_num_coefficients(self, op: u8) -> Self
Constructs a Head Byte which has the same sign and exponent flags as the one specified but also sets the number of following bytes expected to a new value. This is equivalent to with_num_bytes if an exponent is not expected, otherwise this adds 1 and calls the aforementioned function. If the Head Byte indicates the infinity special case, the lack of an exponent is assumed (i.e. 1 is not added to this number), despite the exponent bit being set in such situations.
Panics if the number cannot fit into the Head Byte’s byte count field. The panic message includes the exponent byte in the number of bytes, if expected.
The in-place counterpart is set_coefficient_bytes.
Sourcepub fn set_num_coefficients(&mut self, op: u8)
pub fn set_num_coefficients(&mut self, op: u8)
Sets the number of coefficient bytes which are supposed to follow the Head Byte. This is equivalent to set_num_bytes if an exponent is not expected, otherwise this adds 1 and calls the aforementioned function. If the Head Byte indicates the infinity special case, the lack of an exponent is assumed (i.e. 1 is not added to this number), despite the exponent bit being set in such situations.
Panics if the number cannot fit into the Head Byte’s byte count field. The panic message includes the exponent byte in the number of bytes, if expected.
For a version of this funciton which returns the result instead of performing the operation in-place, see with_num_coefficients.
Sourcepub const fn into_inner(self) -> u8
pub const fn into_inner(self) -> u8
Consumes the value and returns the inner byte.