Struct Fx

Source
pub struct Fx {
    pub val: UInt,
    pub m: i32,
    pub b: i32,
    pub is_exact: bool,
}

Fields§

§val: UInt§m: i32§b: i32§is_exact: bool

Implementations§

Source§

impl Fx

Source

pub fn new(val: UInt, m: i32, b: i32, is_exact: bool) -> Self

Examples found in repository?
examples/basic.rs (line 52)
4fn main() {
5  // let bits = "1010000010110000";
6  // let (m, n) = (1, 15);
7
8  // let b1 = to_Q(0.0, 1, 5, true).unwrap();
9  // println!("{b1:?}");
10
11  // let x = to_float_str(bits, m, n);
12  // println!("bits = {} -> {:?}", bits, x);
13
14  // let bits = 0b1010000010110000;
15  // let x = to_float(bits, 16, m, n);
16  // println!("{:?}", x);
17
18  // let x = 10.25;
19  // let (m, n) = (21, 3);
20
21  // let fx0 = to_Q(x, m, n, true).unwrap();
22  // println!("{:?}", fx0);
23
24  // let fx1 = Q::new(0b10010011, 6, 2, true); // 36.75
25  // let fx2 = Fx::new(0b10010011, 6, 8, true); // 36.75
26
27  // println!("{:?} {} {}", fx1, fx1, fx1.eval());
28  // println!("{:?} {} {}", fx2, fx2, fx2.eval());
29
30  // // let fx1_sliced = fx1.index(7..0);
31  // // println!("{:?}", fx1_sliced);
32
33  // let fx33 = to_Fx(-2.44140625, 4, 12, true);
34  // println!("{fx33:?}");
35
36  // let fixed11 = to_fixed(-2.5, 3, 3, false);
37  // println!("{:?}", fixed11);
38
39  // let fixed22 = to_Fx(10.0, 4, 15, false);
40  // println!("{:?}", fixed22);
41
42  // let fixed23 = to_Fx(5.8, 4, 15, false);
43  // println!("{:?}", fixed23);
44
45  // println!("{:?}", fixed22.unwrap() + fixed23.unwrap());
46
47  // println!("{:?}", to_float(0b1_000, 4, 3, 0));
48
49  // let a = Fx::new(0b11111111111111111111110010100000010001001011000100100110000000000000000000000000000000000000000000000000000000000000000000000000, 31, 128, true);
50  // println!("{:?}", a.eval());
51
52  let m1 = Fx::new(0b0_0001_100, 4, 8, true);
53  let m2 = Fx::new(0b1_1101_010, 4, 8, true);
54  let m = m1 * m2;
55  println!("{:?}", m);
56}
Source

pub fn get_frac_bits(&self) -> i32

Trait Implementations§

Source§

impl Add for Fx

Source§

type Output = Fx

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for Fx

Source§

fn clone(&self) -> Fx

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 Fx

Source§

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

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

impl Display for Fx

Source§

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

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

impl FixedPoint for Fx

Source§

fn eval(&self) -> f64

Source§

impl Mul for Fx

Source§

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

use fixed2float::Fx;
let m = Fx::new(0b0_0001_100, 4, 8, true) * Fx::new(0b1_1101_010, 4, 8, true); // 1.5 * -2.75 == -4.125
let mul = Fx::new(0b1_1011_111, 4, 8, true);
assert_eq!(m, mul);
Source§

type Output = Fx

The resulting type after applying the * operator.
Source§

impl Neg for Fx

Source§

type Output = Fx

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Fx

Source§

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

Source§

type Output = Fx

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Copy for Fx

Source§

impl Eq for Fx

Source§

impl StructuralPartialEq for Fx

Auto Trait Implementations§

§

impl Freeze for Fx

§

impl RefUnwindSafe for Fx

§

impl Send for Fx

§

impl Sync for Fx

§

impl Unpin for Fx

§

impl UnwindSafe for Fx

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.