reorganize modules

This commit is contained in:
Trevor Spiteri 2019-08-20 15:30:23 +02:00
parent 96107159f5
commit 0b4dac8d33
18 changed files with 755 additions and 725 deletions

View File

@ -16,7 +16,7 @@
use crate::{
helpers::IntHelper,
traits::ToFixed,
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
wide_div::WideDivRem,
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
@ -718,11 +718,11 @@ mul_div_fallback! { i128, u128, Signed }
#[cfg(test)]
mod tests {
use crate::{frac::Unsigned, *};
use crate::{types::extra::Unsigned, *};
#[test]
fn fixed_u16() {
use crate::frac::U7 as Frac;
use crate::types::extra::U7 as Frac;
let frac = Frac::U32;
let a = 12;
let b = 4;
@ -742,7 +742,7 @@ mod tests {
#[test]
fn fixed_i16() {
use crate::frac::U7 as Frac;
use crate::types::extra::U7 as Frac;
let frac = Frac::U32;
let a = 12;
let b = 4;
@ -766,7 +766,7 @@ mod tests {
#[test]
fn fixed_u128() {
use crate::frac::U7 as Frac;
use crate::types::extra::U7 as Frac;
let frac = Frac::U32;
let a = 0x0003_4567_89ab_cdef_0123_4567_89ab_cdef_u128;
let b = 5;
@ -788,7 +788,7 @@ mod tests {
#[test]
fn fixed_i128() {
use crate::frac::U7 as Frac;
use crate::types::extra::U7 as Frac;
let frac = Frac::U32;
let a = 0x0003_4567_89ab_cdef_0123_4567_89ab_cdef_i128;
let b = 5;

View File

@ -16,7 +16,7 @@
use crate::{
helpers::{FloatHelper, FloatKind, IntHelper, Widest},
traits::Fixed,
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};
@ -405,8 +405,8 @@ mod tests {
#[test]
fn cmp_signed() {
use core::cmp::Ordering::*;
let neg1_16 = FixedI32::<frac::U16>::from_num(-1);
let neg1_20 = FixedI32::<frac::U20>::from_num(-1);
let neg1_16 = FixedI32::<types::extra::U16>::from_num(-1);
let neg1_20 = FixedI32::<types::extra::U20>::from_num(-1);
let mut a = neg1_16;
let mut b = neg1_20;
// a = ffff.0000 = -1, b = fff.00000 = -1
@ -458,8 +458,8 @@ mod tests {
#[test]
fn cmp_unsigned() {
use core::cmp::Ordering::*;
let one_16 = FixedU32::<frac::U16>::from_num(1);
let one_20 = FixedU32::<frac::U20>::from_num(1);
let one_16 = FixedU32::<types::extra::U16>::from_num(1);
let one_20 = FixedU32::<types::extra::U20>::from_num(1);
let mut a = one_16;
let mut b = one_20;
// a = 0001.0000 = 1, b = 001.00000 = 1

View File

@ -14,10 +14,12 @@
// <https://opensource.org/licenses/MIT>.
use crate::{
frac::{Diff, IsLessOrEqual, True, U0, U1, U127, U128, U15, U16, U31, U32, U63, U64, U7, U8},
helpers::IntHelper,
traits::LossyFrom,
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{
Diff, IsLessOrEqual, LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8, True, U0, U1, U127, U128,
U15, U16, U31, U32, U63, U64, U7, U8,
},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};
@ -700,21 +702,21 @@ fn _compile_fail_tests() {}
#[cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))]
#[cfg(test)]
mod tests {
use crate::*;
use crate::types::*;
#[test]
fn expanding_from_unsigned() {
type L8 = FixedU8<frac::U0>;
type LL16 = FixedU16<frac::U0>;
type LH16 = FixedU16<frac::U8>;
type LL128 = FixedU128<frac::U0>;
type LH128 = FixedU128<frac::U120>;
type L8 = U8F0;
type LL16 = U16F0;
type LH16 = U8F8;
type LL128 = U128F0;
type LH128 = U8F120;
type H8 = FixedU8<frac::U8>;
type HL16 = FixedU16<frac::U8>;
type HH16 = FixedU16<frac::U16>;
type HL128 = FixedU128<frac::U8>;
type HH128 = FixedU128<frac::U128>;
type H8 = U0F8;
type HL16 = U8F8;
type HH16 = U0F16;
type HL128 = U120F8;
type HH128 = U0F128;
let vals: &[u8] = &[0x00, 0x7f, 0x80, 0xff];
for &val in vals {
@ -739,17 +741,17 @@ mod tests {
#[test]
fn expanding_from_signed() {
type L8 = FixedI8<frac::U0>;
type LL16 = FixedI16<frac::U0>;
type LH16 = FixedI16<frac::U8>;
type LL128 = FixedI128<frac::U0>;
type LH128 = FixedI128<frac::U120>;
type L8 = I8F0;
type LL16 = I16F0;
type LH16 = I8F8;
type LL128 = I128F0;
type LH128 = I8F120;
type H8 = FixedI8<frac::U8>;
type HL16 = FixedI16<frac::U8>;
type HH16 = FixedI16<frac::U16>;
type HL128 = FixedI128<frac::U8>;
type HH128 = FixedI128<frac::U128>;
type H8 = I0F8;
type HL16 = I8F8;
type HH16 = I0F16;
type HL128 = I120F8;
type HH128 = I0F128;
let vals: &[i8] = &[0x00, 0x7f, -0x80, -0x01];
for &val in vals {
@ -774,17 +776,17 @@ mod tests {
#[test]
fn expanding_from_unsigned_to_signed() {
type L8 = FixedU8<frac::U0>;
type LL16 = FixedI16<frac::U0>;
type LH16 = FixedI16<frac::U7>;
type LL128 = FixedI128<frac::U0>;
type LH128 = FixedI128<frac::U119>;
type L8 = U8F0;
type LL16 = I16F0;
type LH16 = I9F7;
type LL128 = I128F0;
type LH128 = I9F119;
type H8 = FixedU8<frac::U8>;
type HL16 = FixedI16<frac::U8>;
type HH16 = FixedI16<frac::U15>;
type HL128 = FixedI128<frac::U8>;
type HH128 = FixedI128<frac::U127>;
type H8 = U0F8;
type HL16 = I8F8;
type HH16 = I1F15;
type HL128 = I120F8;
type HH128 = I1F127;
let vals: &[u8] = &[0x00, 0x7f, 0x80, 0xff];
for &val in vals {
@ -809,17 +811,17 @@ mod tests {
#[test]
fn from_bool() {
assert_eq!(FixedI8::<frac::U6>::from(true), 1);
assert_eq!(FixedI8::<frac::U6>::from(false), 0);
assert_eq!(FixedI128::<frac::U64>::from(true), 1);
assert_eq!(FixedU128::<frac::U127>::from(true), 1);
assert_eq!(I2F6::from(true), 1);
assert_eq!(I2F6::from(false), 0);
assert_eq!(I64F64::from(true), 1);
assert_eq!(U1F127::from(true), 1);
}
#[test]
fn to_size() {
let min_i24 = FixedI32::<frac::U8>::min_value();
let max_i24 = FixedI32::<frac::U8>::max_value();
let max_u24 = FixedU32::<frac::U8>::max_value();
let min_i24 = I24F8::min_value();
let max_i24 = I24F8::max_value();
let max_u24 = U24F8::max_value();
assert_eq!(min_i24.overflowing_to_num::<isize>(), (!0 << 23, false));
assert_eq!(max_i24.overflowing_to_num::<isize>(), (!(!0 << 23), false));
assert_eq!(max_u24.overflowing_to_num::<isize>(), (!(!0 << 24), false));
@ -827,9 +829,9 @@ mod tests {
assert_eq!(max_i24.overflowing_to_num::<usize>(), (!(!0 << 23), false));
assert_eq!(max_u24.overflowing_to_num::<usize>(), (!(!0 << 24), false));
let min_i56 = FixedI64::<frac::U8>::min_value();
let max_i56 = FixedI64::<frac::U8>::max_value();
let max_u56 = FixedU64::<frac::U8>::max_value();
let min_i56 = I56F8::min_value();
let max_i56 = I56F8::max_value();
let max_u56 = U56F8::max_value();
#[cfg(target_pointer_width = "32")]
{
assert_eq!(min_i56.overflowing_to_num::<isize>(), (0, true));
@ -849,9 +851,9 @@ mod tests {
assert_eq!(max_u56.overflowing_to_num::<usize>(), (!(!0 << 56), false));
}
let min_i120 = FixedI128::<frac::U8>::min_value();
let max_i120 = FixedI128::<frac::U8>::max_value();
let max_u120 = FixedU128::<frac::U8>::max_value();
let min_i120 = I120F8::min_value();
let max_i120 = I120F8::max_value();
let max_u120 = U120F8::max_value();
assert_eq!(min_i120.overflowing_to_num::<isize>(), (0, true));
assert_eq!(max_i120.overflowing_to_num::<isize>(), (!0, true));
assert_eq!(max_u120.overflowing_to_num::<isize>(), (!0, true));
@ -862,7 +864,7 @@ mod tests {
#[test]
fn signed_from_float() {
type Fix = FixedI8<frac::U4>;
type Fix = I4F4;
// 1.1 -> 0001.1000
assert_eq!(Fix::from_num(3.0 / 2.0), Fix::from_bits(24));
// 0.11 -> 0000.1100
@ -920,7 +922,7 @@ mod tests {
#[test]
fn unsigned_from_num() {
type Fix = FixedU8<frac::U4>;
type Fix = U4F4;
// 1.1 -> 0001.1000
assert_eq!(Fix::from_num(3.0 / 2.0), Fix::from_bits(24));
// 0.11 -> 0000.1100
@ -959,10 +961,10 @@ mod tests {
fn to_f16() {
use half::f16;
for u in 0x00..=0xff {
let fu = FixedU8::<frac::U7>::from_bits(u);
let fu = U1F7::from_bits(u);
assert_eq!(fu.to_num::<f16>(), f16::from_f32(f32::from(u) / 128.0));
let i = u as i8;
let fi = FixedI8::<frac::U7>::from_bits(i);
let fi = I1F7::from_bits(i);
assert_eq!(fi.to_num::<f16>(), f16::from_f32(f32::from(i) / 128.0));
for hi in &[
@ -975,10 +977,10 @@ mod tests {
0xffff_ff00,
] {
let uu = *hi | u32::from(u);
let fuu = FixedU32::<frac::U7>::from_bits(uu);
let fuu = U25F7::from_bits(uu);
assert_eq!(fuu.to_num::<f16>(), f16::from_f32(uu as f32 / 128.0));
let ii = uu as i32;
let fii = FixedI32::<frac::U7>::from_bits(ii);
let fii = I25F7::from_bits(ii);
assert_eq!(fii.to_num::<f16>(), f16::from_f32(ii as f32 / 128.0));
}
@ -992,10 +994,10 @@ mod tests {
0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ff00,
] {
let uu = *hi | u128::from(u);
let fuu = FixedU128::<frac::U7>::from_bits(uu);
let fuu = U121F7::from_bits(uu);
assert_eq!(fuu.to_num::<f16>(), f16::from_f64(uu as f64 / 128.0));
let ii = uu as i128;
let fii = FixedI128::<frac::U7>::from_bits(ii);
let fii = I121F7::from_bits(ii);
assert_eq!(fii.to_num::<f16>(), f16::from_f64(ii as f64 / 128.0));
}
}
@ -1004,10 +1006,10 @@ mod tests {
#[test]
fn to_f32() {
for u in 0x00..=0xff {
let fu = FixedU8::<frac::U7>::from_bits(u);
let fu = U1F7::from_bits(u);
assert_eq!(fu.to_num::<f32>(), f32::from(u) / 128.0);
let i = u as i8;
let fi = FixedI8::<frac::U7>::from_bits(i);
let fi = I1F7::from_bits(i);
assert_eq!(fi.to_num::<f32>(), f32::from(i) / 128.0);
for hi in &[
@ -1020,10 +1022,10 @@ mod tests {
0xffff_ff00,
] {
let uu = *hi | u32::from(u);
let fuu = FixedU32::<frac::U7>::from_bits(uu);
let fuu = U25F7::from_bits(uu);
assert_eq!(fuu.to_num::<f32>(), uu as f32 / 128.0);
let ii = uu as i32;
let fii = FixedI32::<frac::U7>::from_bits(ii);
let fii = I25F7::from_bits(ii);
assert_eq!(fii.to_num::<f32>(), ii as f32 / 128.0);
}
@ -1037,10 +1039,10 @@ mod tests {
0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ff00,
] {
let uu = *hi | u128::from(u);
let fuu = FixedU128::<frac::U7>::from_bits(uu);
let fuu = U121F7::from_bits(uu);
assert_eq!(fuu.to_num::<f32>(), (uu as f64 / 128.0) as f32);
let ii = uu as i128;
let fii = FixedI128::<frac::U7>::from_bits(ii);
let fii = I121F7::from_bits(ii);
assert_eq!(fii.to_num::<f32>(), (ii as f64 / 128.0) as f32);
}
}
@ -1050,7 +1052,7 @@ mod tests {
fn to_infinite_f32() {
// too_large is 1.ffff_ffff_ffff... << 127,
// which will be rounded to 1.0 << 128.
let too_large = FixedU128::<frac::U0>::max_value();
let too_large = U128F0::max_value();
assert_eq!(too_large.count_ones(), 128);
assert!(too_large.to_num::<f32>().is_infinite());
@ -1064,12 +1066,12 @@ mod tests {
// not_too_large is 1.ffff_feff_ffff... << 127,
// which will be rounded to 1.ffff_fe << 127.
let not_too_large = still_too_large - FixedU128::from_bits(1);
let not_too_large = still_too_large - U128F0::from_bits(1);
assert_eq!(not_too_large.count_ones(), 127);
assert!(!not_too_large.to_num::<f32>().is_infinite());
// min_128 is -1.0 << 127.
let min_i128 = FixedI128::<frac::U0>::min_value();
let min_i128 = I128F0::min_value();
assert_eq!(min_i128.count_ones(), 1);
assert_eq!(min_i128.to_num::<f32>(), -(127f32.exp2()));
}
@ -1077,10 +1079,10 @@ mod tests {
#[test]
fn to_f64() {
for u in 0x00..=0xff {
let fu = FixedU8::<frac::U7>::from_bits(u);
let fu = U1F7::from_bits(u);
assert_eq!(fu.to_num::<f64>(), f64::from(u) / 128.0);
let i = u as i8;
let fi = FixedI8::<frac::U7>::from_bits(i);
let fi = I1F7::from_bits(i);
assert_eq!(fi.to_num::<f64>(), f64::from(i) / 128.0);
for hi in &[
@ -1093,10 +1095,10 @@ mod tests {
0xffff_ffff_ffff_ff00,
] {
let uu = *hi | u64::from(u);
let fuu = FixedU64::<frac::U7>::from_bits(uu);
let fuu = U57F7::from_bits(uu);
assert_eq!(fuu.to_num::<f64>(), uu as f64 / 128.0);
let ii = uu as i64;
let fii = FixedI64::<frac::U7>::from_bits(ii);
let fii = I57F7::from_bits(ii);
assert_eq!(fii.to_num::<f64>(), ii as f64 / 128.0);
}
@ -1110,10 +1112,10 @@ mod tests {
0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ff00,
] {
let uu = *hi | u128::from(u);
let fuu = FixedU128::<frac::U7>::from_bits(uu);
let fuu = U121F7::from_bits(uu);
assert_eq!(fuu.to_num::<f64>(), uu as f64 / 128.0);
let ii = uu as i128;
let fii = FixedI128::<frac::U7>::from_bits(ii);
let fii = I121F7::from_bits(ii);
assert_eq!(fii.to_num::<f64>(), ii as f64 / 128.0);
}
}

View File

@ -14,10 +14,9 @@
// <https://opensource.org/licenses/MIT>.
use crate::{
frac::False,
helpers::IntHelper,
traits::Fixed,
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{False, LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};

View File

@ -18,9 +18,10 @@ This module reexports items from the [*typenum* crate].
[*typenum* crate]: https://crates.io/crates/typenum
*/
#![deprecated(since = "0.4.3", note = "replaced by fixed::types::extra")]
pub(crate) use typenum::{Bit, False};
pub use typenum::{
#[deprecated(since = "0.4.3", note = "replaced by types in fixed::types::extra")]
pub use crate::types::extra::{
Diff, IsLessOrEqual, True, Unsigned, U0, U1, U10, U100, U101, U102, U103, U104, U105, U106,
U107, U108, U109, U11, U110, U111, U112, U113, U114, U115, U116, U117, U118, U119, U12, U120,
U121, U122, U123, U124, U125, U126, U127, U128, U13, U14, U15, U16, U17, U18, U19, U2, U20,
@ -30,3 +31,5 @@ pub use typenum::{
U73, U74, U75, U76, U77, U78, U79, U8, U80, U81, U82, U83, U84, U85, U86, U87, U88, U89, U9,
U90, U91, U92, U93, U94, U95, U96, U97, U98, U99,
};
#[deprecated(since = "0.4.3", note = "replaced by types in fixed::types::extra")]
pub use typenum::IsGreaterOrEqual;

View File

@ -15,9 +15,8 @@
use crate::{
display::Mul10,
frac::False,
helpers::IntHelper,
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{False, LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
wide_div::WideDivRem,
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,

View File

@ -15,7 +15,7 @@
pub use crate::{float_helper::FloatHelper, int_helper::IntHelper};
use crate::{
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};

View File

@ -14,9 +14,9 @@
// <https://opensource.org/licenses/MIT>.
use crate::{
frac::{Bit, False, True, Unsigned, U0, U128, U16, U32, U64, U8},
helpers::{ToFixedHelper, Widest},
traits::Fixed,
types::extra::{Bit, False, True, Unsigned, U0, U128, U16, U32, U64, U8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};

View File

@ -74,7 +74,7 @@ assert_eq!(six_and_third.ceil(), 7);
The type [`I20F12`] is a 32-bit fixed-point signed number with 20
integer bits and 12 fractional bits. It is an alias to
<code>[FixedI32][`FixedI32`]&lt;[frac::U12][`frac::U12`]&gt;</code>.
<code>[FixedI32][`FixedI32`]&lt;[U12][`U12`]&gt;</code>.
The unsigned counterpart would be [`U20F12`]. Aliases are provided for
all combinations of integer and fractional bits adding up to a total
of eight, 16, 32, 64 or 128 bits.
@ -195,7 +195,7 @@ additional terms or conditions.
[`ToFixed`]: traits/trait.ToFixed.html
[`U20F12`]: types/type.U20F12.html
[`f16`]: https://docs.rs/half/^1/half/struct.f16.html
[`frac::U12`]: frac/type.U12.html
[`U12`]: types/extra/type.U12.html
[`from_num`]: struct.FixedI8.html#method.from_num
[const generics]: https://github.com/rust-lang/rust/issues/44580
*/
@ -233,7 +233,7 @@ use crate::{
arith::MulDivDir,
from_str::FromStrRadix,
traits::{FromFixed, ToFixed},
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
};
pub use crate::{from_str::ParseFixedError, wrapping::Wrapping};
use core::{
@ -301,7 +301,7 @@ are implemented by the Rust compiler.
# Examples
```rust
use fixed::{frac::U3, ", $s_fixed, "};
use fixed::{types::extra::U3, ", $s_fixed, "};
let eleven = ", $s_fixed, "::<U3>::from_num(11);
assert_eq!(eleven, ", $s_fixed, "::<U3>::from_bits(11 << 3));
assert_eq!(eleven, 11);

View File

@ -26,7 +26,7 @@ macro_rules! fixed_frac {
# Examples
```rust
use fixed::{frac::U6, ", $s_fixed, "};
use fixed::{types::extra::U6, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U6>;
assert_eq!(Fix::INT_NBITS, ", $s_nbits, " - 6);
```
@ -40,7 +40,7 @@ assert_eq!(Fix::INT_NBITS, ", $s_nbits, " - 6);
# Examples
```rust
use fixed::{frac::U6, ", $s_fixed, "};
use fixed::{types::extra::U6, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U6>;
assert_eq!(Fix::FRAC_NBITS, 6);
```
@ -67,7 +67,7 @@ assert_eq!(Fix::FRAC_NBITS, 6);
# Examples
```rust
use fixed::{frac::U6, ", $s_fixed, "};
use fixed::{types::extra::U6, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U6>;
assert_eq!(Fix::int_nbits(), ", $s_nbits, " - 6);
```
@ -84,7 +84,7 @@ assert_eq!(Fix::int_nbits(), ", $s_nbits, " - 6);
# Examples
```rust
use fixed::{frac::U6, ", $s_fixed, "};
use fixed::{types::extra::U6, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U6>;
assert_eq!(Fix::frac_nbits(), 6);
```
@ -119,7 +119,7 @@ represented is almost certainly a bug.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(5).signum(), 1);
assert_eq!(Fix::from_num(0).signum(), 0);
@ -143,7 +143,7 @@ assert_eq!(Fix::from_num(-5).signum(), -1);
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::max_value().checked_mul(Fix::from_num(1)), Some(Fix::max_value()));
assert_eq!(Fix::max_value().checked_mul(Fix::from_num(2)), None);
@ -168,7 +168,7 @@ the divisor is zero or on overflow.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::max_value().checked_div(Fix::from_num(1)), Some(Fix::max_value()));
assert_eq!(Fix::max_value().checked_div(Fix::from_num(1) / 2), None);
@ -195,7 +195,7 @@ assert_eq!(Fix::max_value().checked_div(Fix::from_num(1) / 2), None);
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(3).saturating_mul(Fix::from_num(2)), Fix::from_num(6));
assert_eq!(Fix::max_value().saturating_mul(Fix::from_num(2)), Fix::max_value());
@ -222,7 +222,7 @@ Panics if the divisor is zero.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one_half = Fix::from_num(1) / 2;
assert_eq!(Fix::from_num(1).saturating_div(Fix::from_num(2)), one_half);
@ -246,7 +246,7 @@ assert_eq!(Fix::max_value().saturating_div(one_half), Fix::max_value());
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(3).wrapping_mul(Fix::from_num(2)), Fix::from_num(6));
let wrapped = Fix::from_bits(!0 << 2);
@ -270,7 +270,7 @@ Panics if the divisor is zero.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
assert_eq!(Fix::from_num(3).wrapping_div(Fix::from_num(2)), one_point_5);
@ -295,7 +295,7 @@ overflow has occurred. On overflow, the wrapped value is returned.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(3).overflowing_mul(Fix::from_num(2)), (Fix::from_num(6), false));
let wrapped = Fix::from_bits(!0 << 2);
@ -325,7 +325,7 @@ Panics if the divisor is zero.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
assert_eq!(Fix::from_num(3).overflowing_div(Fix::from_num(2)), (one_point_5, false));

View File

@ -43,7 +43,7 @@ it panics; if wrapping is required use [`wrapping_from_num`] instead.
# Examples
```rust
use fixed::{frac::U4, types::I16F16, ", $s_fixed, "};
use fixed::{types::extra::U4, types::I16F16, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 1.75 is 1.11 in binary
@ -123,7 +123,7 @@ it panics; if wrapping is required use [`wrapping_to_num`] instead.
# Examples
```rust
use fixed::{frac::U4, types::I30F2, ", $s_fixed, "};
use fixed::{types::extra::U4, types::I30F2, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 1.75 is 1.11 in binary
@ -202,7 +202,7 @@ The other number can be:
```rust
use fixed::{
frac::{U2, U4},
types::extra::{U2, U4},
types::I16F16,
", $s_fixed, ",
};
@ -288,7 +288,7 @@ The other number can be:
```rust
use fixed::{
frac::{U0, U4, U6},
types::extra::{U0, U4, U6},
types::I16F16,
", $s_fixed, ",
};
@ -377,7 +377,7 @@ This method panics if the value is a floating-point [NaN].
```rust
use fixed::{
frac::{U2, U4},
types::extra::{U2, U4},
types::I16F16,
", $s_fixed, ",
};
@ -461,7 +461,7 @@ The other number can be:
```rust
use fixed::{
frac::{U0, U4, U6},
types::extra::{U0, U4, U6},
types::I16F16,
", $s_fixed, ",
};
@ -545,7 +545,7 @@ For floating-point numbers, panics if the value is not [finite].
```rust
use fixed::{
frac::{U0, U4},
types::extra::{U0, U4},
types::I16F16,
", $s_fixed, ",
};
@ -621,7 +621,7 @@ The other number can be:
```rust
use fixed::{
frac::{U0, U4, U6},
types::extra::{U0, U4, U6},
types::I16F16,
", $s_fixed, ",
};
@ -708,7 +708,7 @@ For floating-point numbers, panics if the value is not [finite].
```rust
use fixed::{
frac::{U0, U4},
types::extra::{U0, U4},
types::I16F16,
", $s_fixed, ",
};
@ -790,7 +790,7 @@ The other number can be:
```rust
use fixed::{
frac::{U0, U4, U6},
types::extra::{U0, U4, U6},
types::I16F16,
", $s_fixed, ",
};
@ -859,7 +859,7 @@ assert_eq!(one_point_625.overflowing_to_num::<f32>(), (1.625f32, false));
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 1.75 is 1.11 in binary
let f = Fix::from_str_binary(\"1.11\");
@ -886,7 +886,7 @@ assert_eq!(neg, Ok(-check));
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 1.75 is 1.11 in binary, 1.6 in octal
let f = Fix::from_str_octal(\"1.6\");
@ -913,7 +913,7 @@ assert_eq!(neg, Ok(-check));
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 1.75 is 1.11 in binary, 1.C in hexadecimal
let f = Fix::from_str_hex(\"1.C\");

View File

@ -26,7 +26,7 @@ macro_rules! fixed_no_frac {
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::min_value(), Fix::from_bits(", $s_inner, "::min_value()));
```
@ -43,7 +43,7 @@ assert_eq!(Fix::min_value(), Fix::from_bits(", $s_inner, "::min_value()));
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::max_value(), Fix::from_bits(", $s_inner, "::max_value()));
```
@ -61,7 +61,7 @@ representation identical to the given integer.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 0010.0000 == 2
assert_eq!(Fix::from_bits(0b10_0000), 2);
@ -83,7 +83,7 @@ identical to the given fixed-point number.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 2 is 0010.0000
assert_eq!(Fix::from_num(2).to_bits(), 0b10_0000);
@ -102,7 +102,7 @@ representation.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let f = Fix::from_bits(0b11_0010);
assert_eq!(f.count_ones(), 3);
@ -117,7 +117,7 @@ representation.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let f = Fix::from_bits(!0b11_0010);
assert_eq!(f.count_zeros(), 3);
@ -132,7 +132,7 @@ representation.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let f = Fix::from_bits(0b10_0000);
assert_eq!(f.leading_zeros(), ", $s_nbits, " - 6);
@ -147,7 +147,7 @@ representation.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let f = Fix::from_bits(0b10_0000);
assert_eq!(f.trailing_zeros(), 5);
@ -162,7 +162,7 @@ truncated bits to the right end.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let bits: ", $s_inner, " = (0b111 << (", $s_nbits, " - 3)) | 0b1010;
let rot = 0b1010111;
@ -179,7 +179,7 @@ truncated bits to the left end.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let bits: ", $s_inner, " = 0b1010111;
let rot = (0b111 << (", $s_nbits, " - 3)) | 0b1010;
@ -198,7 +198,7 @@ assert_eq!(Fix::from_bits(bits).rotate_right(3), Fix::from_bits(rot));
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let five = Fix::from_num(5);
let minus_five = Fix::from_num(-5);
@ -224,7 +224,7 @@ assert_eq!(minus_five.abs(), five);
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
",
if_signed_unsigned!(
@ -251,7 +251,7 @@ assert_eq!(Fix::from_num(5).checked_neg(), None);",
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one = Fix::from_num(1);
assert_eq!((Fix::max_value() - one).checked_add(one), Some(Fix::max_value()));
@ -272,7 +272,7 @@ assert_eq!(Fix::max_value().checked_add(one), None);
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one = Fix::from_num(1);
assert_eq!((Fix::min_value() + one).checked_sub(one), Some(Fix::min_value()));
@ -294,7 +294,7 @@ product, or [`None`] on overflow.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::max_value().checked_mul_int(1), Some(Fix::max_value()));
assert_eq!(Fix::max_value().checked_mul_int(2), None);
@ -321,7 +321,7 @@ assert_eq!(Fix::max_value().checked_mul_int(2), None);
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::max_value().checked_div_int(1), Some(Fix::max_value()));
assert_eq!(Fix::from_num(1).checked_div_int(0), None);
@ -354,7 +354,7 @@ Returns the remainder, or [`None`] if the divisor is zero",
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// binary 1.0101 / 8 = binary 0.0010 remainder 0.0101
assert_eq!(Fix::from_bits(0b10101).checked_rem_int(8), Some(Fix::from_bits(0b101)));
@ -382,7 +382,7 @@ or [`None`] if `rhs` ≥ ", $s_nbits, ".
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!((Fix::from_num(1) / 2).checked_shl(3), Some(Fix::from_num(4)));
assert_eq!((Fix::from_num(1) / 2).checked_shl(", $s_nbits, "), None);
@ -403,7 +403,7 @@ or [`None`] if `rhs` ≥ ", $s_nbits, ".
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(4).checked_shr(3), Some(Fix::from_num(1) / 2));
assert_eq!(Fix::from_num(4).checked_shr(", $s_nbits, "), None);
@ -427,7 +427,7 @@ Overflow can only occur when trying to find the absolute value of the minimum va
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(-5).checked_abs(), Some(Fix::from_num(5)));
assert_eq!(Fix::min_value().checked_abs(), None);
@ -456,7 +456,7 @@ assert_eq!(Fix::min_value().checked_abs(), None);
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
",
if_signed_unsigned!(
@ -485,7 +485,7 @@ assert_eq!(Fix::from_num(5).saturating_neg(), Fix::from_num(0));",
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(3).saturating_add(Fix::from_num(2)), Fix::from_num(5));
assert_eq!(Fix::max_value().saturating_add(Fix::from_num(1)), Fix::max_value());
@ -503,7 +503,7 @@ assert_eq!(Fix::max_value().saturating_add(Fix::from_num(1)), Fix::max_value());
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
",
if_signed_unsigned!(
@ -528,7 +528,7 @@ assert_eq!(Fix::from_num(0).saturating_sub(Fix::from_num(1)), Fix::from_num(0));
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(3).saturating_mul_int(2), Fix::from_num(6));
assert_eq!(Fix::max_value().saturating_mul_int(2), Fix::max_value());
@ -550,7 +550,7 @@ Overflow can only occur when trying to find the absolute value of the minimum va
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(-5).saturating_abs(), Fix::from_num(5));
assert_eq!(Fix::min_value().saturating_abs(), Fix::max_value());
@ -577,7 +577,7 @@ assert_eq!(Fix::min_value().saturating_abs(), Fix::max_value());
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
",
if_signed_unsigned!(
@ -604,7 +604,7 @@ assert_eq!(Fix::from_num(5).wrapping_neg(), Fix::from_bits(neg_five_bits));",
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one = Fix::from_num(1);
let one_minus_bit = one - Fix::from_bits(1);
@ -626,7 +626,7 @@ assert_eq!(Fix::max_value().wrapping_add(one), ",
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one = Fix::from_num(1);
let one_minus_bit = one - Fix::from_bits(1);
@ -653,7 +653,7 @@ assert_eq!(Fix::from_num(0)",
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(3).wrapping_mul_int(2), Fix::from_num(6));
let wrapped = Fix::from_bits(!0 << 2);
@ -686,7 +686,7 @@ Panics if the divisor is zero.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 1.5 is binary 1.1
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
@ -725,7 +725,7 @@ Panics if the divisor is zero.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// binary 1.0101 / 8 = binary 0.0010 remainder 0.0101
assert_eq!(Fix::from_bits(0b10101).wrapping_rem_int(8), Fix::from_bits(0b101));
@ -750,7 +750,7 @@ then shifts and returns the number.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!((Fix::from_num(1) / 2).wrapping_shl(3), Fix::from_num(4));
assert_eq!((Fix::from_num(1) / 2).wrapping_shl(3 + ", $s_nbits, "), Fix::from_num(4));
@ -766,7 +766,7 @@ then shifts and returns the number.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!((Fix::from_num(4)).wrapping_shr(3), Fix::from_num(1) / 2);
assert_eq!((Fix::from_num(4)).wrapping_shr(3 + ", $s_nbits, "), Fix::from_num(1) / 2);
@ -785,7 +785,7 @@ Overflow can only occur when trying to find the absolute value of the minimum va
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(-5).wrapping_abs(), Fix::from_num(5));
assert_eq!(Fix::min_value().wrapping_abs(), Fix::min_value());
@ -812,7 +812,7 @@ an overflow has occurred. On overflow, the wrapped value is returned.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
",
if_signed_unsigned!(
@ -846,7 +846,7 @@ overflow has occurred. On overflow, the wrapped value is returned.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one = Fix::from_num(1);
let one_minus_bit = one - Fix::from_bits(1);
@ -875,7 +875,7 @@ overflow has occurred. On overflow, the wrapped value is returned.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let one = Fix::from_num(1);
let one_minus_bit = one - Fix::from_bits(1);
@ -909,7 +909,7 @@ overflow has occurred. On overflow, the wrapped value is returned.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(3).overflowing_mul_int(2), (Fix::from_num(6), false));
let wrapped = Fix::from_bits(!0 << 2);
@ -946,7 +946,7 @@ Panics if the divisor is zero.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 1.5 is binary 1.1
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
@ -989,7 +989,7 @@ Panics if the divisor is zero.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// binary 1.0101 / 8 = binary 0.0010 remainder 0.0101
assert_eq!(Fix::from_bits(0b10101).overflowing_rem_int(8), (Fix::from_bits(0b101), false));
@ -1021,7 +1021,7 @@ On overflow `rhs` is wrapped before the shift operation.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!((Fix::from_num(1) / 2).overflowing_shl(3), (Fix::from_num(4), false));
assert_eq!((Fix::from_num(1) / 2).overflowing_shl(3 + ", $s_nbits, "), (Fix::from_num(4), true));
@ -1047,7 +1047,7 @@ On overflow `rhs` is wrapped before the shift operation.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!((Fix::from_num(4)).overflowing_shr(3), (Fix::from_num(1) / 2, false));
assert_eq!((Fix::from_num(4)).overflowing_shr(3 + ", $s_nbits, "), (Fix::from_num(1) / 2, true));
@ -1077,7 +1077,7 @@ Overflow can only occur when trying to find the absolute value of the minimum va
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_num(-5).overflowing_abs(), (Fix::from_num(5), false));
assert_eq!(Fix::min_value().overflowing_abs(), (Fix::min_value(), true));
@ -1103,7 +1103,7 @@ assert_eq!(Fix::min_value().overflowing_abs(), (Fix::min_value(), true));
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 3/8 is 0.0110
let three_eights = Fix::from_bits(0b0110);
@ -1134,7 +1134,7 @@ future it panics.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 3/8 is 0.0110
let three_eights = Fix::from_bits(0b0110);
@ -1154,7 +1154,7 @@ assert_eq!(half.next_power_of_two(), half);
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 3/8 is 0.0110
let three_eights = Fix::from_bits(0b0110);
@ -1181,7 +1181,7 @@ assert!(Fix::max_value().checked_next_power_of_two().is_none());
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert!(Fix::from_num(5).is_positive());
assert!(!Fix::from_num(0).is_positive());
@ -1199,7 +1199,7 @@ assert!(!Fix::from_num(-5).is_positive());
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert!(!Fix::from_num(5).is_negative());
assert!(!Fix::from_num(0).is_negative());

View File

@ -31,7 +31,7 @@ bits, that is `", $s_fixed, "<U", $s_nbits, ">`, where the return value is alway
"# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 0010.0000
let two = Fix::from_num(2);
@ -72,7 +72,7 @@ numbers, except in the case where there are no integer bits, that is
"# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 0000.0100
let quarter = Fix::from_num(1) / 4;
@ -109,7 +109,7 @@ it panics; if wrapping is required use [`wrapping_ceil`] instead.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.ceil(), Fix::from_num(3));
@ -152,7 +152,7 @@ Overflow can only occur when there are zero integer bits.
"# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.floor(), Fix::from_num(2));
@ -189,7 +189,7 @@ it panics; if wrapping is required use [`wrapping_round`] instead.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, r"<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.round(), Fix::from_num(3));
@ -219,7 +219,7 @@ returning [`None`] on overflow.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.checked_ceil(), Some(Fix::from_num(3)));
@ -260,11 +260,11 @@ use fixed::{",
$Signedness,
concat!(
"
frac::{U4, U", $s_nbits, "},
types::extra::{U4, U", $s_nbits, "},
", $s_fixed, ",
",
),
concat!("frac::U4, ", $s_fixed),
concat!("types::extra::U4, ", $s_fixed),
),
"};
type Fix = ", $s_fixed, "<U4>;
@ -303,7 +303,7 @@ rounded away from zero, returning [`None`] on overflow.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.checked_round(), Some(Fix::from_num(3)));
@ -332,7 +332,7 @@ saturating on overflow.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.saturating_ceil(), Fix::from_num(3));
@ -371,11 +371,11 @@ use fixed::{",
$Signedness,
concat!(
"
frac::{U4, U", $s_nbits, "},
types::extra::{U4, U", $s_nbits, "},
", $s_fixed, ",
",
),
concat!("frac::U4, ", $s_fixed),
concat!("types::extra::U4, ", $s_fixed),
),
"};
type Fix = ", $s_fixed, "<U4>;
@ -405,7 +405,7 @@ ties rounded away from zero, and saturating on overflow.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.saturating_round(), Fix::from_num(3));
@ -437,7 +437,7 @@ wrapping on overflow.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.wrapping_ceil(), Fix::from_num(3));
@ -475,11 +475,11 @@ use fixed::{",
$Signedness,
concat!(
"
frac::{U4, U", $s_nbits, "},
types::extra::{U4, U", $s_nbits, "},
", $s_fixed, ",
",
),
concat!("frac::U4, ", $s_fixed),
concat!("types::extra::U4, ", $s_fixed),
),
"};
type Fix = ", $s_fixed, "<U4>;
@ -508,7 +508,7 @@ nearest, with ties rounded away from zero, and wrapping on overflow.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.wrapping_round(), Fix::from_num(3));
@ -537,7 +537,7 @@ returned.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.overflowing_ceil(), (Fix::from_num(3), false));
@ -595,11 +595,11 @@ use fixed::{",
$Signedness,
concat!(
"
frac::{U4, U", $s_nbits, "},
types::extra::{U4, U", $s_nbits, "},
", $s_fixed, ",
",
),
concat!("frac::U4, ", $s_fixed),
concat!("types::extra::U4, ", $s_fixed),
),
"};
type Fix = ", $s_fixed, "<U4>;
@ -642,7 +642,7 @@ returned.
# Examples
```rust
use fixed::{frac::U4, ", $s_fixed, "};
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
let two_half = Fix::from_num(5) / 2;
assert_eq!(two_half.overflowing_round(), (Fix::from_num(3), false));

View File

@ -21,7 +21,7 @@ This module contains sealed traits.
use crate::{
traits::Fixed as TraitsFixed,
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};

View File

@ -14,7 +14,7 @@
// <https://opensource.org/licenses/MIT>.
use crate::{
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};

View File

@ -19,7 +19,7 @@ This module contains traits.
use crate::{
helpers::{FloatHelper, FloatKind, FromFloatHelper, IntHelper, Sealed, Widest},
types::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8, ParseFixedError,
};

50
src/types/extra.rs Normal file
View File

@ -0,0 +1,50 @@
// Copyright © 20182019 Trevor Spiteri
// This library is free software: you can redistribute it and/or
// modify it under the terms of either
//
// * the Apache License, Version 2.0 or
// * the MIT License
//
// at your option.
//
// You should have recieved copies of the Apache License and the MIT
// License along with the library. If not, see
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
/*!
Extra types that do not need to be handled directly.
These types are mostly reexports from the [*typenum* crate].
[*typenum* crate]: https://crates.io/crates/typenum
*/
pub(crate) use typenum::{Bit, False};
pub use typenum::{
Diff, IsLessOrEqual, True, Unsigned, U0, U1, U10, U100, U101, U102, U103, U104, U105, U106,
U107, U108, U109, U11, U110, U111, U112, U113, U114, U115, U116, U117, U118, U119, U12, U120,
U121, U122, U123, U124, U125, U126, U127, U128, U13, U14, U15, U16, U17, U18, U19, U2, U20,
U21, U22, U23, U24, U25, U26, U27, U28, U29, U3, U30, U31, U32, U33, U34, U35, U36, U37, U38,
U39, U4, U40, U41, U42, U43, U44, U45, U46, U47, U48, U49, U5, U50, U51, U52, U53, U54, U55,
U56, U57, U58, U59, U6, U60, U61, U62, U63, U64, U65, U66, U67, U68, U69, U7, U70, U71, U72,
U73, U74, U75, U76, U77, U78, U79, U8, U80, U81, U82, U83, U84, U85, U86, U87, U88, U89, U9,
U90, U91, U92, U93, U94, U95, U96, U97, U98, U99,
};
/// Implemented for all [`Unsigned`](trait.Unsigned.html) integers ≤ 8.
pub trait LeEqU8: Unsigned + IsLessOrEqual<U8, Output = True> {}
impl<T: Unsigned + IsLessOrEqual<U8, Output = True>> LeEqU8 for T {}
/// Implemented for all [`Unsigned`](trait.Unsigned.html) integers ≤ 16.
pub trait LeEqU16: Unsigned + IsLessOrEqual<U16, Output = True> {}
impl<T: Unsigned + IsLessOrEqual<U16, Output = True>> LeEqU16 for T {}
/// Implemented for all [`Unsigned`](trait.Unsigned.html) integers ≤ 32.
pub trait LeEqU32: Unsigned + IsLessOrEqual<U32, Output = True> {}
impl<T: Unsigned + IsLessOrEqual<U32, Output = True>> LeEqU32 for T {}
/// Implemented for all [`Unsigned`](trait.Unsigned.html) integers ≤ 64.
pub trait LeEqU64: Unsigned + IsLessOrEqual<U64, Output = True> {}
impl<T: Unsigned + IsLessOrEqual<U64, Output = True>> LeEqU64 for T {}
/// Implemented for all [`Unsigned`](trait.Unsigned.html) integers ≤ 128.
pub trait LeEqU128: Unsigned + IsLessOrEqual<U128, Output = True> {}
impl<T: Unsigned + IsLessOrEqual<U128, Output = True>> LeEqU128 for T {}

File diff suppressed because it is too large Load Diff