pub struct Fixed(/* private fields */);Expand description
The OpenType Fixed type, a 16.16-bit signed fixed-point type.
Implementations§
Source§impl Fixed
impl Fixed
Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this type.
§Examples
assert_eq!(Fixed::MIN, -32768.0);Sourcepub const MAX: Self
pub const MAX: Self
The largest value that can be represented by this type.
§Examples
assert_eq!(Fixed::MAX, 32767.99998474121);Sourcepub const fn new(num: f64) -> Option<Self>
pub const fn new(num: f64) -> Option<Self>
Creates a Fixed from f64,
returning None if the value is out of Fixed’s range.
§Examples
use ttf_view::types::Fixed;
assert_eq!(Fixed::new(-0.125).unwrap(), -0.125);
assert_eq!(Fixed::new(1.99609375).unwrap(), 1.99609375);
assert_eq!(Fixed::new(-34000.0), None);
assert_eq!(Fixed::new(34000.0), None);
assert_eq!(Fixed::new(f64::NAN), None);
// numbers are rounded towards the closest value representable by Fixed
assert_eq!(Fixed::new(0.5156247).unwrap(), 0.515625);
assert_eq!(Fixed::new(0.5156250).unwrap(), 0.515625);
assert_eq!(Fixed::new(0.5156254).unwrap(), 0.515625);Sourcepub const fn new_saturating(num: f64) -> Self
pub const fn new_saturating(num: f64) -> Self
Creates a Fixed from f64,
saturating at the numeric bounds, and mapping NaN to 0.
§Examples
use ttf_view::types::Fixed;
assert_eq!(Fixed::new_saturating(-0.125), -0.125);
assert_eq!(Fixed::new_saturating(1.99609375), 1.99609375);
assert_eq!(Fixed::new_saturating(-34000.0), -32768.0);
assert_eq!(Fixed::new_saturating(34000.0), 32767.99998474121);
assert_eq!(Fixed::new_saturating(f64::NAN), 0.0);
// numbers are rounded towards the closest value representable by Fixed
assert_eq!(Fixed::new_saturating(0.5156247), 0.515625);
assert_eq!(Fixed::new_saturating(0.5156250), 0.515625);
assert_eq!(Fixed::new_saturating(0.5156254), 0.515625);Sourcepub const fn from_be_bytes(bytes: [u8; 4]) -> Self
pub const fn from_be_bytes(bytes: [u8; 4]) -> Self
Creates a Fixed from big-endian bytes.
Sourcepub const fn to_be_bytes(self) -> [u8; 4]
pub const fn to_be_bytes(self) -> [u8; 4]
Gets this Fixed’s big-endian bytes.
Sourcepub const fn from_frac_num(numerator: i32) -> Self
pub const fn from_frac_num(numerator: i32) -> Self
Creates a Fixed from its integer fraction’s numerator
(Fixed represented as numerator/65536).
Sourcepub const fn frac_num(self) -> i32
pub const fn frac_num(self) -> i32
Returns this Fixed’s integer fraction’s numerator
(Fixed represented as numerator/65536).
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 Fixed
Source§impl Div for Fixed
Performs division / (panics on overflow in debug configuration).
impl Div for Fixed
Performs division / (panics on overflow in debug configuration).
§Panics
This operation will panic if rhs == 0.
impl Eq for Fixed
Source§impl Ord for Fixed
impl Ord for Fixed
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 Fixed
impl PartialOrd for Fixed
Source§impl PartialOrd<f64> for Fixed
impl PartialOrd<f64> for Fixed
Source§impl Rem for Fixed
Performs remainder operation % (panics on overflow in debug configuration).
impl Rem for Fixed
Performs remainder operation % (panics on overflow in debug configuration).
§Panics
This operation will panic if rhs == 0.