tweak quick example in README
This commit is contained in:
parent
4250151943
commit
f2d5f232d4
|
@ -76,12 +76,12 @@ use fixed::FixedI32;
|
||||||
|
|
||||||
// 20 integer bits, 12 fractional bits
|
// 20 integer bits, 12 fractional bits
|
||||||
type I20F12 = FixedI32<frac::U12>;
|
type I20F12 = FixedI32<frac::U12>;
|
||||||
// 25/4 = 6 1/4
|
// 19/3 = 6 1/3
|
||||||
let six_and_quarter = I20F12::from_int(25).unwrap() / 4;
|
let six_and_third = I20F12::from_int(19).unwrap() / 3;
|
||||||
// four decimal digits for 12 binary digits
|
// four decimal digits for 12 binary digits
|
||||||
assert_eq!(six_and_quarter.to_string(), "6.2500");
|
assert_eq!(six_and_third.to_string(), "6.3333");
|
||||||
// convert to i32, taking the ceil
|
// convert to i32, taking the ceil
|
||||||
assert_eq!(six_and_quarter.to_int_ceil(), 7);
|
assert_eq!(six_and_third.to_int_ceil(), 7);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using the *fixed* crate
|
## Using the *fixed* crate
|
||||||
|
|
|
@ -65,7 +65,6 @@ macro_rules! fixed_num_common {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn take_int_dec_digit(int_part: &mut $Part) -> u8 {
|
fn take_int_dec_digit(int_part: &mut $Part) -> u8 {
|
||||||
println!("int part {}", int_part);
|
|
||||||
let ret = (*int_part % 10) as u8;
|
let ret = (*int_part % 10) as u8;
|
||||||
*int_part /= 10;
|
*int_part /= 10;
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -50,12 +50,12 @@ use fixed::FixedI32;
|
||||||
|
|
||||||
// 20 integer bits, 12 fractional bits
|
// 20 integer bits, 12 fractional bits
|
||||||
type I20F12 = FixedI32<frac::U12>;
|
type I20F12 = FixedI32<frac::U12>;
|
||||||
// 25/4 = 6 1/4
|
// 19/3 = 6 1/3
|
||||||
let six_and_quarter = I20F12::from_int(25).unwrap() / 4;
|
let six_and_third = I20F12::from_int(19).unwrap() / 3;
|
||||||
// four decimal digits for 12 binary digits
|
// four decimal digits for 12 binary digits
|
||||||
assert_eq!(six_and_quarter.to_string(), "6.2500");
|
assert_eq!(six_and_third.to_string(), "6.3333");
|
||||||
// convert to i32, taking the ceil
|
// convert to i32, taking the ceil
|
||||||
assert_eq!(six_and_quarter.to_int_ceil(), 7);
|
assert_eq!(six_and_third.to_int_ceil(), 7);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using the *fixed* crate
|
## Using the *fixed* crate
|
||||||
|
|
Loading…
Reference in New Issue