pub struct Scaled(pub i32);
Expand description
Scaled numbers.
This is a fixed-width numeric type used in throughout TeX. This type is defined and described in part 7 “arithmetic with scaled dimensions” starting at TeX.2021.99.
This numeric type has 15 bits for the integer part, 16 bits for the fractional part, and a single signed bit. The inner value is the number multiplied by 2^16.
Tuple Fields§
§0: i32
Implementations§
source§impl Scaled
impl Scaled
sourcepub const MAX_DIMEN: Scaled = _
pub const MAX_DIMEN: Scaled = _
Maximum possible dimension in TeX, which is (2^30-1)/2^16.
This is not the maximum size of the Rust scaled number type, which is (2^31-1)/2^16.
Defined in TeX.2021.421.
sourcepub fn from_integer(i: i32) -> Result<Scaled, OverflowError>
pub fn from_integer(i: i32) -> Result<Scaled, OverflowError>
Create a scaled number corresponding the provided positive integer.
Scaled numbers are in the range (-2^14, 2^14)
.
If i is outside this range an overflow error is returned.
sourcepub fn from_decimal_digits(digits: &[u8]) -> Scaled
pub fn from_decimal_digits(digits: &[u8]) -> Scaled
Creates a scaled number from a decimal fraction.
TeX.2021.102.
sourcepub fn new(
integer_part: i32,
fractional_part: Scaled,
scaled_unit: ScaledUnit,
) -> Result<Scaled, OverflowError>
pub fn new( integer_part: i32, fractional_part: Scaled, scaled_unit: ScaledUnit, ) -> Result<Scaled, OverflowError>
Creates a scaled number from the provided components.
TeX.2021.458
sourcepub fn xn_over_d(
&self,
n: i32,
d: i32,
) -> Result<(Scaled, Scaled), OverflowError>
pub fn xn_over_d( &self, n: i32, d: i32, ) -> Result<(Scaled, Scaled), OverflowError>
Calculates the integer division xn/d and remainder, where x is this scaled number
and n and d are integers in the range [0,2^16]
.
This function appears in TeX.2021.107. Knuth is working with 32-bit integers
and so calculating this number is tricky without overflowing. E.g. xn may
be larger than 2^32-1
even if the final result is in range.
TeX has an algorithm that calculates the exact value without overflowing,
in the case when the final result is in range.
Our implementation simply uses 64-bit integers.
pub fn integer_part(self) -> i32
pub fn fractional_part(self) -> Scaled
pub fn abs(self) -> Scaled
pub fn wrapping_add(self, rhs: Scaled) -> Self
pub fn checked_add(self, rhs: Scaled) -> Option<Self>
pub fn wrapping_mul(self, rhs: i32) -> Self
pub fn checked_mul(self, rhs: i32) -> Option<Self>
pub fn checked_div(self, rhs: i32) -> Option<Self>
pub fn display_no_units(self) -> impl Display
Trait Implementations§
source§impl<'de> Deserialize<'de> for Scaled
impl<'de> Deserialize<'de> for Scaled
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Ord for Scaled
impl Ord for Scaled
source§impl PartialOrd for Scaled
impl PartialOrd for Scaled
impl Copy for Scaled
impl Eq for Scaled
impl StructuralPartialEq for Scaled
Auto Trait Implementations§
impl Freeze for Scaled
impl RefUnwindSafe for Scaled
impl Send for Scaled
impl Sync for Scaled
impl Unpin for Scaled
impl UnwindSafe for Scaled
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)