Struct core::Scaled

source ·
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

source

pub const ZERO: Scaled = _

Representation of the number 0 as a Scaled.

source

pub const ONE: Scaled = _

Representation of the number 1 as a Scaled.

source

pub const TWO: Scaled = _

Representation of the number 2 as a Scaled.

source

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.

source

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.

source

pub fn from_decimal_digits(digits: &[u8]) -> Scaled

Creates a scaled number from a decimal fraction.

TeX.2021.102.

source

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

source

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.

source

pub fn nx_plus_y(self, n: i32, y: Scaled) -> Result<Scaled, OverflowError>

TeX.2021.105

source

pub fn integer_part(self) -> i32

source

pub fn fractional_part(self) -> Scaled

source

pub fn abs(self) -> Scaled

source

pub fn wrapping_add(self, rhs: Scaled) -> Self

source

pub fn checked_add(self, rhs: Scaled) -> Option<Self>

source

pub fn wrapping_mul(self, rhs: i32) -> Self

source

pub fn checked_mul(self, rhs: i32) -> Option<Self>

source

pub fn checked_div(self, rhs: i32) -> Option<Self>

source

pub fn display_no_units(self) -> impl Display

Trait Implementations§

source§

impl Add for Scaled

source§

type Output = Scaled

The resulting type after applying the + operator.
source§

fn add(self, rhs: Scaled) -> Self::Output

Performs the + operation. Read more
source§

impl Clone for Scaled

source§

fn clone(&self) -> Scaled

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Scaled

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Scaled

source§

fn default() -> Scaled

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Scaled

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Scaled

source§

fn fmt(&self, fm: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<i32> for Scaled

source§

type Output = Scaled

The resulting type after applying the / operator.
source§

fn div(self, rhs: i32) -> Self::Output

Performs the / operation. Read more
source§

impl Hash for Scaled

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Mul<i32> for Scaled

source§

type Output = Scaled

The resulting type after applying the * operator.
source§

fn mul(self, rhs: i32) -> Self::Output

Performs the * operation. Read more
source§

impl Neg for Scaled

source§

type Output = Scaled

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Ord for Scaled

source§

fn cmp(&self, other: &Scaled) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Scaled

source§

fn eq(&self, other: &Scaled) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Scaled

source§

fn partial_cmp(&self, other: &Scaled) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Rem<i32> for Scaled

source§

type Output = Scaled

The resulting type after applying the % operator.
source§

fn rem(self, rhs: i32) -> Self::Output

Performs the % operation. Read more
source§

impl Serialize for Scaled

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sub for Scaled

source§

type Output = Scaled

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Scaled) -> Self::Output

Performs the - operation. Read more
source§

impl Copy for Scaled

source§

impl Eq for Scaled

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,