pub struct F2Dot14(/* private fields */);Expand description
The OpenType F2Dot14 type, a 2.14-bit signed fixed-point type.
Implementations§
Source§impl F2Dot14
impl F2Dot14
Sourcepub const MAX: Self
pub const MAX: Self
The largest value that can be represented by this type.
§Examples
assert_eq!(F2Dot14::MAX, 1.999939);Sourcepub const fn new(num: f32) -> Option<Self>
pub const fn new(num: f32) -> Option<Self>
Creates a F2Dot14 from f32,
returning None if the value is out of F2Dot14’s range.
§Examples
use ttf_view::types::F2Dot14;
assert_eq!(F2Dot14::new(-0.125).unwrap(), -0.125);
assert_eq!(F2Dot14::new(1.99609375).unwrap(), 1.99609375);
assert_eq!(F2Dot14::new(-34000.0), None);
assert_eq!(F2Dot14::new(34000.0), None);
assert_eq!(F2Dot14::new(f32::NAN), None);
// numbers are rounded towards the closest value representable by F2Dot14
assert_eq!(F2Dot14::new(0.5156247).unwrap(), 0.515625);
assert_eq!(F2Dot14::new(0.5156250).unwrap(), 0.515625);
assert_eq!(F2Dot14::new(0.5156254).unwrap(), 0.515625);Sourcepub const fn new_saturating(num: f32) -> Self
pub const fn new_saturating(num: f32) -> Self
Creates a F2Dot14 from f32,
saturating at the numeric bounds, and mapping NaN to 0.
§Examples
use ttf_view::types::F2Dot14;
assert_eq!(F2Dot14::new_saturating(-0.125), -0.125);
assert_eq!(F2Dot14::new_saturating(1.99609375), 1.99609375);
assert_eq!(F2Dot14::new_saturating(-34000.0), -2.0);
assert_eq!(F2Dot14::new_saturating(34000.0), 1.999939);
assert_eq!(F2Dot14::new_saturating(f32::NAN), 0.0);
// numbers are rounded towards the closest value representable by F2Dot14
assert_eq!(F2Dot14::new_saturating(0.5156247), 0.515625);
assert_eq!(F2Dot14::new_saturating(0.5156250), 0.515625);
assert_eq!(F2Dot14::new_saturating(0.5156254), 0.515625);Sourcepub const fn from_be_bytes(bytes: [u8; 2]) -> Self
pub const fn from_be_bytes(bytes: [u8; 2]) -> Self
Creates a F2Dot14 from big-endian bytes.
Sourcepub const fn to_be_bytes(self) -> [u8; 2]
pub const fn to_be_bytes(self) -> [u8; 2]
Gets this F2Dot14’s big-endian bytes.
Sourcepub const fn from_frac_num(numerator: i16) -> Self
pub const fn from_frac_num(numerator: i16) -> Self
Creates a F2Dot14 from its integer fraction’s numerator
(F2Dot14 represented as numerator/16384).
Sourcepub const fn frac_num(self) -> i16
pub const fn frac_num(self) -> i16
Returns this F2Dot14’s integer fraction’s numerator
(F2Dot14 represented as numerator/16384).
pub const fn wrapping_neg(self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Sourcepub const fn wrapping_div(self, rhs: Self) -> Self
pub const fn wrapping_div(self, rhs: Self) -> Self
§Panics
This function panics if rhs == 0.
Sourcepub const fn wrapping_rem(self, rhs: Self) -> Self
pub const fn wrapping_rem(self, rhs: Self) -> Self
§Panics
This function panics if rhs == 0.
pub const fn saturating_neg(self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Sourcepub const fn saturating_div(self, rhs: Self) -> Self
pub const fn saturating_div(self, rhs: Self) -> Self
§Panics
This function panics if rhs == 0.
pub const fn checked_neg(self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_rem(self, rhs: Self) -> Option<Self>
Trait Implementations§
impl Copy for F2Dot14
Source§impl Div for F2Dot14
Performs division / (panics on overflow in debug configuration).
impl Div for F2Dot14
Performs division / (panics on overflow in debug configuration).
§Panics
This operation will panic if rhs == 0.
impl Eq for F2Dot14
Source§impl Ord for F2Dot14
impl Ord for F2Dot14
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for F2Dot14
impl PartialOrd for F2Dot14
Source§impl PartialOrd<f32> for F2Dot14
impl PartialOrd<f32> for F2Dot14
Source§impl Rem for F2Dot14
Performs remainder operation % (panics on overflow in debug configuration).
impl Rem for F2Dot14
Performs remainder operation % (panics on overflow in debug configuration).
§Panics
This operation will panic if rhs == 0.