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: i32Implementations§
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 AddAssign for Scaled
impl AddAssign for Scaled
Source§fn add_assign(&mut self, rhs: Scaled)
fn add_assign(&mut self, rhs: Scaled)
+= operation. Read moreSource§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 DivAssign<i32> for Scaled
impl DivAssign<i32> for Scaled
Source§fn div_assign(&mut self, rhs: i32)
fn div_assign(&mut self, rhs: i32)
/= operation. Read more