[−][src]Struct bigbit::headbyte::Exponent
An exponent for the Head Byte and Extended Head Byte formats.
To retreive the real value of an [E]HB number, its stored value is multiplied by 10 raised to the power of this value as retreived using into_inner
.
This is not a 2's complement signed number: it ranges from -127 to +127, having one bit as the sign and the rest as a normal 7-bit unsigned integer. As a consequence, it's possible to store 0b1_0000000
as the exponent, meaning a resulting exponent of 10⁻⁰, which is undefined. In most cases, this transformation is unwanted (that is, accidential, most likely happening because of a serious mistake during bitwise operations), and as such is not allowed, producing a TryFrom
error.
In other words, protection against -0
is a safety guarantee, and actually creating an exponent with this value requires unsafe code.
Methods
impl Exponent
[src]
pub const SIGN_MASK: u8
[src]
The sign bit mask.
Use sign
to easily retreive the sign.
pub const ABS_MASK: u8
[src]
pub unsafe fn from_u8_unchecked(op: u8) -> Self
[src]
Wraps a byte into an exponent, ignoring the invalid 0b1_0000000
case.
This is the unsafe unchecked version of the TryFrom
implementation.
Safety
The value must never be 0b1_0000000
(-0
), since avoiding that case is a safety guaranteee of the Exponent
type.
pub fn sign(self) -> Sign
[src]
Retreives the sign from the exponent. Negative
means that the coefficient is multiplied by 10 raised to the power of -n
, where n
is the rest of the exponent byte, and Positive
simply means 10^n
.
#[must_use = "this is not an in-place operation"]pub fn abs(self) -> Self
[src]
Retreives the absolute value of the exponent, i.e. removes the minus in 10^-n
if it exists.
#[must_use = "this is not an in-place operation"]pub fn invert(self) -> Self
[src]
Inverts the sign bit of the exponent. 10^2
(0b0000_0010
) becomes 10^-2
(0b1000_0010
), 10^127
→ 10^-127
and so on.
#[must_use = "this is not an in-place operation"]pub fn checked_mul(self, rhs: Self) -> Option<Self>
[src]
#[must_use]pub fn into_inner(self) -> u8
[src]
Consumes the value and returns the inner byte.
See the struct-level documentation for the meaning of this value.
Trait Implementations
impl Clone for Exponent
[src]
fn clone(&self) -> Exponent
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Exponent
[src]
impl Debug for Exponent
[src]
impl Eq for Exponent
[src]
impl From<Exponent> for u8
[src]
#[must_use]fn from(op: Exponent) -> Self
[src]
Consumes the exponent and returns the underlying inner byte.
impl PartialEq<Exponent> for Exponent
[src]
impl StructuralEq for Exponent
[src]
impl StructuralPartialEq for Exponent
[src]
impl TryFrom<u8> for Exponent
[src]
type Error = InvalidExponentError
The type returned in the event of a conversion error.
fn try_from(op: u8) -> Result<Self, InvalidExponentError>
[src]
Wraps a byte into an exponent.
Errors
If the supplied value is 0b1_0000000
(-0
), Err(InvalidExponentError)
is returned, where InvalidExponentError
is a marker error type.
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,