The crate provides the following types:
FixedI8is a signed eight-bit fixed-point number,
FixedI16is a signed 16-bit fixed-point number,
FixedI32is a signed 32-bit fixed-point number,
FixedI64is a signed 64-bit fixed-point number,
FixedI128is a signed 128-bit fixed-point number,
FixedU8is an unsigned eight-bit fixed-point number,
FixedU16is an unsigned 16-bit fixed-point number,
FixedU32is an unsigned 32-bit fixed-point number,
FixedU64is an unsigned 64-bit fixed-point number, and
FixedU128is an unsigned 128-bit fixed-point number.
All fixed-point numbers can have
Frac fractional bits, where
can have any value from 0 up to and including the size of the number
in bits. When
Frac is 0, the fixed-point number behaves like an
Frac is equal to the number of bits, the value of the
fixed-point number lies in the range −0.5 ≤ x < 0.5 for signed
fixed-point numbers, and in the range 0 ≤ x < 1 for unsigned
use fixed::frac; use fixed::FixedI32; // 20 integer bits, 12 fractional bits type I20F12 = FixedI32<frac::U12>; // 19/3 = 6 1/3 let six_and_third = I20F12::from_int(19).unwrap() / 3; // four decimal digits for 12 binary digits assert_eq!(six_and_third.to_string(), "6.3333"); // convert to i32, taking the ceil assert_eq!(six_and_third.to_int_ceil(), 7);
[dependencies] fixed = "0.1.1"
You also need to declare it by adding this to your crate root (usually lib.rs or main.rs):
extern crate fixed;
This crate is free software: you can redistribute it and/or modify it under the terms of either
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache License, Version 2.0, shall be dual licensed as above, without any additional terms or conditions.
This module reexports items from the typenum crate.
An eight-bit fixed-point signed integer
A 16-bit fixed-point signed integer
A 32-bit fixed-point signed integer
A 64-bit fixed-point signed integer
A 128-bit fixed-point signed integer
An eight-bit fixed-point unsigned integer
A 16-bit fixed-point unsigned integer
A 32-bit fixed-point unsigned integer
A 64-bit fixed-point unsigned integer
A 128-bit fixed-point unsigned integer