doc tweaks

This commit is contained in:
Trevor Spiteri 2021-03-20 22:49:07 +01:00
parent fa1cecc104
commit 3cd0053e62
3 changed files with 32 additions and 23 deletions

View File

@ -849,7 +849,10 @@ that is ≤ `self`.
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
assert_eq!(Fix::from_bits(0b11_0010).highest_one(), Fix::from_bits(0b10_0000));
assert_eq!(Fix::from_num(3.125).highest_one(), Fix::from_num(2));
assert_eq!(Fix::from_num(0.3).highest_one(), Fix::from_num(0.25));
assert_eq!(Fix::from_num(4).highest_one(), Fix::from_num(4));
assert_eq!(Fix::from_num(6.5).highest_one(), Fix::from_num(4));
assert_eq!(Fix::from_num(0).highest_one(), Fix::from_num(0));
```
";
#[inline]
@ -880,12 +883,10 @@ future it panics; if this is not desirable use
```rust
use fixed::{types::extra::U4, ", $s_fixed, "};
type Fix = ", $s_fixed, "<U4>;
// 3/8 is 0.0110
let three_eights = Fix::from_bits(0b0110);
// 1/2 is 0.1000
let half = Fix::from_bits(0b1000);
assert_eq!(three_eights.next_power_of_two(), half);
assert_eq!(half.next_power_of_two(), half);
assert_eq!(Fix::from_bits(0b11_0010).next_power_of_two(), Fix::from_bits(0b100_0000));
assert_eq!(Fix::from_num(0.3).next_power_of_two(), Fix::from_num(0.5));
assert_eq!(Fix::from_num(4).next_power_of_two(), Fix::from_num(4));
assert_eq!(Fix::from_num(6.5).next_power_of_two(), Fix::from_num(8));
```
[`checked_next_power_of_two`]: #method.checked_next_power_of_two

View File

@ -1182,10 +1182,13 @@ impl<F: FixedUnsigned> Unwrapped<F> {
/// # Examples
///
/// ```rust
/// use fixed::{types::U4F4, Unwrapped};
/// type T = Unwrapped<U4F4>;
/// use fixed::{types::U16F16, Unwrapped};
/// type T = Unwrapped<U16F16>;
/// assert_eq!(T::from_bits(0b11_0010).highest_one(), T::from_bits(0b10_0000));
/// assert_eq!(T::from_num(3.125).highest_one(), T::from_num(2));
/// assert_eq!(T::from_num(0.3).highest_one(), T::from_num(0.25));
/// assert_eq!(T::from_num(4).highest_one(), T::from_num(4));
/// assert_eq!(T::from_num(6.5).highest_one(), T::from_num(4));
/// assert_eq!(T::from_num(0).highest_one(), T::from_num(0));
/// ```
#[inline]
pub fn highest_one(self) -> Unwrapped<F> {
@ -1202,10 +1205,11 @@ impl<F: FixedUnsigned> Unwrapped<F> {
///
/// ```rust
/// use fixed::{types::U16F16, Unwrapped};
/// let half = Unwrapped(U16F16::from_num(0.5));
/// assert_eq!(Unwrapped(U16F16::from_num(0.3)).next_power_of_two(), half);
/// let four = Unwrapped(U16F16::from_num(4));
/// assert_eq!(Unwrapped(U16F16::from_num(4)).next_power_of_two(), four);
/// type T = Unwrapped<U16F16>;
/// assert_eq!(T::from_bits(0b11_0010).next_power_of_two(), T::from_bits(0b100_0000));
/// assert_eq!(T::from_num(0.3).next_power_of_two(), T::from_num(0.5));
/// assert_eq!(T::from_num(4).next_power_of_two(), T::from_num(4));
/// assert_eq!(T::from_num(6.5).next_power_of_two(), T::from_num(8));
/// ```
///
/// The following panics because of overflow.

View File

@ -1099,10 +1099,13 @@ impl<F: FixedUnsigned> Wrapping<F> {
/// # Examples
///
/// ```rust
/// use fixed::{types::U4F4, Wrapping};
/// type T = Wrapping<U4F4>;
/// use fixed::{types::U16F16, Wrapping};
/// type T = Wrapping<U16F16>;
/// assert_eq!(T::from_bits(0b11_0010).highest_one(), T::from_bits(0b10_0000));
/// assert_eq!(T::from_num(3.125).highest_one(), T::from_num(2));
/// assert_eq!(T::from_num(0.3).highest_one(), T::from_num(0.25));
/// assert_eq!(T::from_num(4).highest_one(), T::from_num(4));
/// assert_eq!(T::from_num(6.5).highest_one(), T::from_num(4));
/// assert_eq!(T::from_num(0).highest_one(), T::from_num(0));
/// ```
#[inline]
pub fn highest_one(self) -> Wrapping<F> {
@ -1117,12 +1120,13 @@ impl<F: FixedUnsigned> Wrapping<F> {
///
/// ```rust
/// use fixed::{types::U16F16, Wrapping};
/// let half = Wrapping(U16F16::from_num(0.5));
/// assert_eq!(Wrapping(U16F16::from_num(0.3)).next_power_of_two(), half);
/// let four = Wrapping(U16F16::from_num(4));
/// assert_eq!(Wrapping(U16F16::from_num(4)).next_power_of_two(), four);
/// let zero = Wrapping(U16F16::from_num(0));
/// assert_eq!(Wrapping(U16F16::MAX).next_power_of_two(), zero);
/// type T = Wrapping<U16F16>;
/// assert_eq!(T::from_bits(0b11_0010).next_power_of_two(), T::from_bits(0b100_0000));
/// assert_eq!(T::from_num(0.3).next_power_of_two(), T::from_num(0.5));
/// assert_eq!(T::from_num(4).next_power_of_two(), T::from_num(4));
/// assert_eq!(T::from_num(6.5).next_power_of_two(), T::from_num(8));
/// // if the next power of two is too large, it is wrapped to zero
/// assert_eq!(T::MAX.next_power_of_two(), T::from_num(0));
/// ```
#[inline]
pub fn next_power_of_two(self) -> Wrapping<F> {