Fixed8

Struct Fixed8 

Source
pub struct Fixed8(/* private fields */);
Expand description

A signed fixed-point value with $frac_bits bits.

Implementations§

Source§

impl Fixed8

A signed fixed-point type.

Source

pub const INTEGER_BITS: u8 = 8u8

The number of integer bits.

Source

pub const FRACTIONAL_BITS: u8 = 8u8

The number of fractional bits.

Source

pub const ZERO: Self

The fixed-point value representing 0.0.

Source

pub const ONE: Self

The fixed-point value representing 1.0.

Source

pub const MIN: Self

The minimum representable value of this type.

Source

pub const MAX: Self

The maximum representable value of this type.

Source

pub const fn from_bits(n: i16) -> Self

Returns the fixed-point value with the same bit-representation as the given value.

Source

pub const fn get(self) -> i16

Source

pub fn from_f32(n: f32) -> Self

Converts an f32 floating-point value to fixed point.

This conversion may be lossy, with behavior like standard Rust float-to-int casting. Extra precision will be truncated, and the result will be saturated if it doesn’t fit in the underlying type’s range. NaN returns 0.0.

Examples found in repository?
examples/writing.rs (line 13)
3fn main() {
4    let header = Header {
5        compression: Compression::Zlib,
6        version: 6,
7        stage_size: Rectangle {
8            x_min: Twips::ZERO,
9            x_max: Twips::from_pixels(400.0),
10            y_min: Twips::ZERO,
11            y_max: Twips::from_pixels(400.0),
12        },
13        frame_rate: Fixed8::from_f32(60.0),
14        num_frames: 1,
15    };
16    let tags = [
17        Tag::SetBackgroundColor(Color {
18            r: 255,
19            g: 0,
20            b: 0,
21            a: 255,
22        }),
23        Tag::ShowFrame,
24    ];
25    let file = std::fs::File::create("tests/swfs/SimpleRedBackground.swf").unwrap();
26    let writer = std::io::BufWriter::new(file);
27    swf::write_swf(&header, &tags, writer).unwrap();
28}
Source

pub fn from_f64(n: f64) -> Self

Converts an f64 floating-point value to fixed-point.

This conversion may be lossy, with behavior like standard Rust float-to-int casting. Extra precision will be truncated, and the result will be saturated if it doesn’t fit in the underlying type’s range. NaN returns 0.0.

Source

pub fn to_f32(self) -> f32

Converts this fixed-point value to f32 floating-point.

This conversion may be lossy if f32 does not have enough precision to represent the fixed-point value.

Use From to ensure that the conversion is lossless at compile-time.

Source

pub fn to_f64(self) -> f64

Converts this fixed-point value to f64 floating-point.

This conversion may be lossy if f64 does not have enough precision to represent the fixed-point value.

Use From to ensure that the conversion is lossless at compile-time.

Source

pub const fn is_zero(self) -> bool

Returns true if this is equal to 0.0.

Source

pub const fn is_one(self) -> bool

Returns true if this is equal to 1.0.

Source

pub fn mul_int(self, other: i16) -> i16

Multiplies this fixed-point by an integer, returning the integer result. The result uses full range of the integer. The fractional bits will be truncated.

Source

pub const fn wrapping_neg(self) -> Self

Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type. -Self::MIN is the only case where wrapping occurs.

Source

pub const fn wrapping_add(self, other: Self) -> Self

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

Source

pub const fn wrapping_sub(self, other: Self) -> Self

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

Source

pub const fn wrapping_mul(self, other: Self) -> Self

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

Source

pub const fn wrapping_div(self, other: Self) -> Self

Wrapping (modular) division. Computes self / rhs, wrapping around at the boundary of the type.

Source

pub const fn wrapping_mul_int(self, other: i16) -> i16

Wrapping (modular) multiplication. Multiplies this fixed-point by an integer, returning the integer result. The result will use the full size of the integer. The fractional bits will be truncated.

Trait Implementations§

Source§

impl Add for Fixed8

Source§

type Output = Fixed8

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Fixed8

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl Clone for Fixed8

Source§

fn clone(&self) -> Fixed8

Returns a duplicate 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 Fixed8

Source§

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

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

impl Default for Fixed8

Source§

fn default() -> Self

Returns the default value of 0.0.

Source§

impl Display for Fixed8

Source§

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

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

impl Div<i16> for Fixed8

Source§

type Output = Fixed8

The resulting type after applying the / operator.
Source§

fn div(self, other: i16) -> Self

Performs the / operation. Read more
Source§

impl Div for Fixed8

Source§

type Output = Fixed8

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Self

Performs the / operation. Read more
Source§

impl DivAssign<i16> for Fixed8

Source§

fn div_assign(&mut self, other: i16)

Performs the /= operation. Read more
Source§

impl DivAssign for Fixed8

Source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
Source§

impl From<Fixed8> for f32

Source§

fn from(n: Fixed8) -> f32

Converts to this type from the input type.
Source§

impl From<Fixed8> for f64

Source§

fn from(n: Fixed8) -> f64

Converts to this type from the input type.
Source§

impl From<i8> for Fixed8

Source§

fn from(n: i8) -> Self

Converts to this type from the input type.
Source§

impl Hash for Fixed8

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<Fixed8> for i16

Source§

type Output = Fixed8

The resulting type after applying the * operator.
Source§

fn mul(self, other: Fixed8) -> Fixed8

Performs the * operation. Read more
Source§

impl Mul<i16> for Fixed8

Source§

type Output = Fixed8

The resulting type after applying the * operator.
Source§

fn mul(self, other: i16) -> Self

Performs the * operation. Read more
Source§

impl Mul for Fixed8

Source§

type Output = Fixed8

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl MulAssign<i16> for Fixed8

Source§

fn mul_assign(&mut self, other: i16)

Performs the *= operation. Read more
Source§

impl MulAssign for Fixed8

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl Neg for Fixed8

Source§

type Output = Fixed8

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Ord for Fixed8

Source§

fn cmp(&self, other: &Fixed8) -> 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,

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

impl PartialEq for Fixed8

Source§

fn eq(&self, other: &Fixed8) -> 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 Fixed8

Source§

fn partial_cmp(&self, other: &Fixed8) -> 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 Sub for Fixed8

Source§

type Output = Fixed8

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for Fixed8

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl Copy for Fixed8

Source§

impl Eq for Fixed8

Source§

impl StructuralPartialEq for Fixed8

Auto Trait Implementations§

§

impl Freeze for Fixed8

§

impl RefUnwindSafe for Fixed8

§

impl Send for Fixed8

§

impl Sync for Fixed8

§

impl Unpin for Fixed8

§

impl UnwindSafe for Fixed8

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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§

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.