doc: update docs since now f16 conversions are always provided

This commit is contained in:
Trevor Spiteri 2021-03-26 20:05:11 +01:00
parent 2d146ccb75
commit d8d252b989
3 changed files with 81 additions and 91 deletions

View File

@ -25,10 +25,9 @@ The other number can be:
* An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`], * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`],
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. [`usize`].
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds
For this conversion, the method rounds to the nearest, with ties to the nearest, with ties rounding to even.
rounding to even.
* Any other number `src` for which [`ToFixed`] is implemented, in * Any other number `src` for which [`ToFixed`] is implemented, in
which case this method returns [`src.to_fixed()`][`to_fixed`]. which case this method returns [`src.to_fixed()`][`to_fixed`].
@ -70,9 +69,9 @@ assert_eq!(Fix::from_num(",
"0b111 << (4-2))); "0b111 << (4-2)));
``` ```
[`F128Bits`]: struct.F128Bits.html
[`ToFixed`]: traits/trait.ToFixed.html [`ToFixed`]: traits/trait.ToFixed.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -109,10 +108,9 @@ The other number can be:
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. Any fractional bits are discarded, which rounds towards [`usize`]. Any fractional bits are discarded, which rounds towards
. .
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other type `Dst` for which [`FromFixed`] is implemented, in * Any other type `Dst` for which [`FromFixed`] is implemented, in
which case this method returns which case this method returns
[`Dst::from_fixed(self)`][`from_fixed`]. [`Dst::from_fixed(self)`][`from_fixed`].
@ -159,9 +157,9 @@ assert_eq!(",
"1.625f64); "1.625f64);
``` ```
[`F128Bits`]: struct.F128Bits.html
[`FromFixed`]: traits/trait.FromFixed.html [`FromFixed`]: traits/trait.FromFixed.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -197,10 +195,9 @@ The other number can be:
* An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`], * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`],
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. [`usize`].
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other number `src` for which [`ToFixed`] is implemented, in * Any other number `src` for which [`ToFixed`] is implemented, in
which case this method returns [`src.checked_to_fixed()`][`checked_to_fixed`]. which case this method returns [`src.checked_to_fixed()`][`checked_to_fixed`].
@ -246,10 +243,10 @@ assert!(Fix::checked_from_num(2e38).is_none());
assert!(Fix::checked_from_num(std::f64::NAN).is_none()); assert!(Fix::checked_from_num(std::f64::NAN).is_none());
``` ```
[`F128Bits`]: struct.F128Bits.html
[`None`]: https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.None [`None`]: https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.None
[`ToFixed`]: traits/trait.ToFixed.html [`ToFixed`]: traits/trait.ToFixed.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -285,10 +282,9 @@ The other number can be:
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. Any fractional bits are discarded, which rounds towards [`usize`]. Any fractional bits are discarded, which rounds towards
. .
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other type `Dst` for which [`FromFixed`] is implemented, in * Any other type `Dst` for which [`FromFixed`] is implemented, in
which case this method returns which case this method returns
[`Dst::checked_from_fixed(self)`][`checked_from_fixed`]. [`Dst::checked_from_fixed(self)`][`checked_from_fixed`].
@ -334,11 +330,11 @@ let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.checked_to_num::<f32>(), Some(1.625f32)); assert_eq!(one_point_625.checked_to_num::<f32>(), Some(1.625f32));
``` ```
[`F128Bits`]: struct.F128Bits.html
[`FromFixed`]: traits/trait.FromFixed.html [`FromFixed`]: traits/trait.FromFixed.html
[`None`]: https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.None [`None`]: https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.None
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`checked_from_fixed`]: traits/trait.FromFixed.html#tymethod.checked_from_fixed [`checked_from_fixed`]: traits/trait.FromFixed.html#tymethod.checked_from_fixed
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -372,10 +368,9 @@ The other number can be:
* An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`], * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`],
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. [`usize`].
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other number `src` for which [`ToFixed`] is implemented, in * Any other number `src` for which [`ToFixed`] is implemented, in
which case this method returns which case this method returns
[`src.saturating_to_fixed()`][`saturating_to_fixed`]. [`src.saturating_to_fixed()`][`saturating_to_fixed`].
@ -425,9 +420,9 @@ assert_eq!(Fix::saturating_from_num(std::f64::NEG_INFINITY), Fix::MIN);
``` ```
[NaN]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_nan [NaN]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_nan
[`F128Bits`]: struct.F128Bits.html
[`ToFixed`]: traits/trait.ToFixed.html [`ToFixed`]: traits/trait.ToFixed.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -463,10 +458,9 @@ The other number can be:
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. Any fractional bits are discarded, which rounds towards [`usize`]. Any fractional bits are discarded, which rounds towards
. .
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other type `Dst` for which [`FromFixed`] is implemented, in * Any other type `Dst` for which [`FromFixed`] is implemented, in
which case this method returns which case this method returns
[`Dst::saturating_from_fixed(self)`][`saturating_from_fixed`]. [`Dst::saturating_from_fixed(self)`][`saturating_from_fixed`].
@ -509,9 +503,9 @@ let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.saturating_to_num::<f32>(), 1.625f32); assert_eq!(one_point_625.saturating_to_num::<f32>(), 1.625f32);
``` ```
[`F128Bits`]: struct.F128Bits.html
[`FromFixed`]: traits/trait.FromFixed.html [`FromFixed`]: traits/trait.FromFixed.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -546,10 +540,9 @@ The other number can be:
* An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`], * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`],
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. [`usize`].
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other number `src` for which [`ToFixed`] is implemented, in * Any other number `src` for which [`ToFixed`] is implemented, in
which case this method returns [`src.wrapping_to_fixed()`][`wrapping_to_fixed`]. which case this method returns [`src.wrapping_to_fixed()`][`wrapping_to_fixed`].
@ -589,9 +582,9 @@ let wrapped = Fix::from_bits(0b1100 << (", $s_nbits, " - 4));
assert_eq!(Fix::wrapping_from_num(large), wrapped); assert_eq!(Fix::wrapping_from_num(large), wrapped);
``` ```
[`F128Bits`]: struct.F128Bits.html
[`ToFixed`]: traits/trait.ToFixed.html [`ToFixed`]: traits/trait.ToFixed.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -628,10 +621,9 @@ The other number can be:
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. Any fractional bits are discarded, which rounds towards [`usize`]. Any fractional bits are discarded, which rounds towards
. .
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other type `Dst` for which [`FromFixed`] is implemented, in * Any other type `Dst` for which [`FromFixed`] is implemented, in
which case this method returns which case this method returns
[`Dst::wrapping_from_fixed(self)`][`wrapping_from_fixed`]. [`Dst::wrapping_from_fixed(self)`][`wrapping_from_fixed`].
@ -674,10 +666,9 @@ let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.wrapping_to_num::<f32>(), 1.625f32); assert_eq!(one_point_625.wrapping_to_num::<f32>(), 1.625f32);
``` ```
[`F128Bits`]: struct.F128Bits.html
[`FromFixed`]: traits/trait.FromFixed.html [`FromFixed`]: traits/trait.FromFixed.html
[`wrapping_from_fixed`]: traits/trait.FromFixed.html#tymethod.wrapping_from_fixed
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -693,6 +684,7 @@ assert_eq!(one_point_625.wrapping_to_num::<f32>(), 1.625f32);
[`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html
[`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
[`wrapping_from_fixed`]: traits/trait.FromFixed.html#tymethod.wrapping_from_fixed
"; ";
#[inline] #[inline]
pub fn wrapping_to_num<Dst: FromFixed>(self) -> Dst { pub fn wrapping_to_num<Dst: FromFixed>(self) -> Dst {
@ -711,10 +703,9 @@ The other number can be:
* An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`], * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`],
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. [`usize`].
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other number `src` for which [`ToFixed`] is implemented. * Any other number `src` for which [`ToFixed`] is implemented.
# Panics # Panics
@ -749,9 +740,9 @@ let too_large = ", $s_fixed, "::<U0>::from_bits(0b1101 << (", $s_nbits, " - 7));
let _overflow = Fix::unwrapped_from_num(too_large); let _overflow = Fix::unwrapped_from_num(too_large);
``` ```
[`F128Bits`]: struct.F128Bits.html
[`ToFixed`]: traits/trait.ToFixed.html [`ToFixed`]: traits/trait.ToFixed.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -791,10 +782,9 @@ The other number can be:
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. Any fractional bits are discarded, which rounds towards [`usize`]. Any fractional bits are discarded, which rounds towards
. .
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other type `Dst` for which [`FromFixed`] is implemented. * Any other type `Dst` for which [`FromFixed`] is implemented.
# Panics # Panics
@ -828,9 +818,9 @@ type TooFewIntBits = ", $s_fixed, "<U6>;
let _overflow = Fix::MAX.unwrapped_to_num::<TooFewIntBits>(); let _overflow = Fix::MAX.unwrapped_to_num::<TooFewIntBits>();
``` ```
[`F128Bits`]: struct.F128Bits.html
[`FromFixed`]: traits/trait.FromFixed.html [`FromFixed`]: traits/trait.FromFixed.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -871,10 +861,9 @@ The other number can be:
* An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`], * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`],
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. [`usize`].
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. For this [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
conversion, the method rounds to the nearest, with ties rounding the nearest, with ties rounding to even.
to even.
* Any other number `src` for which [`ToFixed`] is implemented, in * Any other number `src` for which [`ToFixed`] is implemented, in
which case this method returns [`src.overflowing_to_fixed()`][`overflowing_to_fixed`]. which case this method returns [`src.overflowing_to_fixed()`][`overflowing_to_fixed`].
@ -916,10 +905,10 @@ let wrapped = Fix::from_bits(0b1100 << (", $s_nbits, " - 4));
assert_eq!(Fix::overflowing_from_num(large), (wrapped, true)); assert_eq!(Fix::overflowing_from_num(large), (wrapped, true));
``` ```
[`F128Bits`]: struct.F128Bits.html
[`ToFixed`]: traits/trait.ToFixed.html [`ToFixed`]: traits/trait.ToFixed.html
[`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -959,10 +948,9 @@ The other number can be:
[`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
[`usize`]. Any fractional bits are discarded, which rounds towards [`usize`]. Any fractional bits are discarded, which rounds towards
. .
* A floating-point number of type [`f32`] or [`f64`]. If the [`f16` * A floating-point number of type [`f16`], [`bf16`], [`f32`],
feature] is enabled, it can also be of type [`f16`] or [`bf16`]. [`f64`] or [`F128Bits`]. For this conversion, the method rounds to
For this conversion, the method rounds to the nearest, with ties the nearest, with ties rounding to even.
rounding to even.
* Any other type `Dst` for which [`FromFixed`] is implemented, in * Any other type `Dst` for which [`FromFixed`] is implemented, in
which case this method returns which case this method returns
[`Dst::overflowing_from_fixed(self)`][`overflowing_from_fixed`]. [`Dst::overflowing_from_fixed(self)`][`overflowing_from_fixed`].
@ -1007,10 +995,10 @@ let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.overflowing_to_num::<f32>(), (1.625f32, false)); assert_eq!(one_point_625.overflowing_to_num::<f32>(), (1.625f32, false));
``` ```
[`F128Bits`]: struct.F128Bits.html
[`FromFixed`]: traits/trait.FromFixed.html [`FromFixed`]: traits/trait.FromFixed.html
[`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
[`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
[`f16` feature]: index.html#optional-features [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
[`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html

View File

@ -349,11 +349,12 @@ impl<F: Fixed> Unwrapped<F> {
/// * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`], /// * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`],
/// [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or /// [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
/// [`usize`]. /// [`usize`].
/// * A floating-point number of type [`f32`] or [`f64`]. If the /// * A floating-point number of type [`f16`], [`bf16`],
/// [`f16` feature] is enabled, it can also be of type [`f16`] /// [`f32`], [`f64`] or [`F128Bits`]. For this conversion, the
/// or [`bf16`]. For this conversion, the method rounds to the /// method rounds to the nearest, with ties rounding to even.
/// nearest, with ties rounding to even. /// * Any other number `src` for which [`ToFixed`] is
/// * Any other number `src` for which [`ToFixed`] is implemented. /// implemented, in which case this method returns
/// <code>[Unwrapped][`Unwrapped`]([src.unwrapped_to_fixed()][`unwrapped_to_fixed`])</code>.
/// ///
/// # Panics /// # Panics
/// ///
@ -384,10 +385,10 @@ impl<F: Fixed> Unwrapped<F> {
/// let _overflow = Unwrapped::<I4F4>::from_num(src); /// let _overflow = Unwrapped::<I4F4>::from_num(src);
/// ``` /// ```
/// ///
/// [`F128Bits`]: struct.F128Bits.html
/// [`ToFixed`]: traits/trait.ToFixed.html /// [`ToFixed`]: traits/trait.ToFixed.html
/// [`Unwrapped`]: struct.Unwrapped.html /// [`Unwrapped`]: struct.Unwrapped.html
/// [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html /// [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
/// [`f16` feature]: index.html#optional-features
/// [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html /// [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
/// [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html /// [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
/// [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html /// [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -402,6 +403,7 @@ impl<F: Fixed> Unwrapped<F> {
/// [`u32`]: https://doc.rust-lang.org/nightly/std/primitive.u32.html /// [`u32`]: https://doc.rust-lang.org/nightly/std/primitive.u32.html
/// [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html /// [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html
/// [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html /// [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html
/// [`unwrapped_to_fixed`]: traits/trait.ToFixed.html#method.unwrapped_to_fixed
/// [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html /// [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
/// [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite /// [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
#[inline] #[inline]
@ -423,11 +425,12 @@ impl<F: Fixed> Unwrapped<F> {
/// [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or /// [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
/// [`usize`]. Any fractional bits are discarded, which rounds /// [`usize`]. Any fractional bits are discarded, which rounds
/// towards −∞. /// towards −∞.
/// * A floating-point number of type [`f32`] or [`f64`]. If the /// * A floating-point number of type [`f16`], [`bf16`],
/// [`f16` feature] is enabled, it can also be of type [`f16`] /// [`f32`], [`f64`] or [`F128Bits`]. For this conversion, the
/// or [`bf16`]. For this conversion, the method rounds to the /// method rounds to the nearest, with ties rounding to even.
/// nearest, with ties rounding to even. /// * Any other type `Dst` for which [`FromFixed`] is
/// * Any other type `Dst` for which [`FromFixed`] is implemented. /// implemented, in which case this method returns
/// [`Dst::unwrapped_from_fixed(self.0)`][`unwrapped_from_fixed`].
/// ///
/// # Examples /// # Examples
/// ///
@ -451,9 +454,9 @@ impl<F: Fixed> Unwrapped<F> {
/// let _overflow = src.to_num::<I2F6>(); /// let _overflow = src.to_num::<I2F6>();
/// ``` /// ```
/// ///
/// [`F128Bits`]: struct.F128Bits.html
/// [`FromFixed`]: traits/trait.FromFixed.html /// [`FromFixed`]: traits/trait.FromFixed.html
/// [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html /// [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
/// [`f16` feature]: index.html#optional-features
/// [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html /// [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
/// [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html /// [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
/// [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html /// [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -468,6 +471,7 @@ impl<F: Fixed> Unwrapped<F> {
/// [`u32`]: https://doc.rust-lang.org/nightly/std/primitive.u32.html /// [`u32`]: https://doc.rust-lang.org/nightly/std/primitive.u32.html
/// [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html /// [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html
/// [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html /// [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html
/// [`unwrapped_from_fixed`]: traits/trait.FromFixed.html#method.unwrapped_from_fixed
/// [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html /// [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
#[inline] #[inline]
pub fn to_num<Dst: FromFixed>(self) -> Dst { pub fn to_num<Dst: FromFixed>(self) -> Dst {

View File

@ -346,12 +346,11 @@ impl<F: Fixed> Wrapping<F> {
/// * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`], /// * An integer of type [`i8`], [`i16`], [`i32`], [`i64`], [`i128`],
/// [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or /// [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
/// [`usize`]. /// [`usize`].
/// * A floating-point number of type [`f32`] or [`f64`]. If the /// * A floating-point number of type [`f16`], [`bf16`],
/// [`f16` feature] is enabled, it can also be of type [`f16`] /// [`f32`], [`f64`] or [`F128Bits`]. For this conversion, the
/// or [`bf16`]. For this conversion, the method rounds to the /// method rounds to the nearest, with ties rounding to even.
/// nearest, with ties rounding to even. /// * Any other number `src` for which [`ToFixed`] is
/// * Any other number `src` for which [`ToFixed`] is implemented, in /// implemented, in which case this method returns
/// which case this method returns
/// <code>[Wrapping][`Wrapping`]([src.wrapping_to_fixed()][`wrapping_to_fixed`])</code>. /// <code>[Wrapping][`Wrapping`]([src.wrapping_to_fixed()][`wrapping_to_fixed`])</code>.
/// ///
/// # Panics /// # Panics
@ -382,10 +381,10 @@ impl<F: Fixed> Wrapping<F> {
/// assert_eq!(dst_float, Wrapping(I4F4::from_bits(0b11100))); /// assert_eq!(dst_float, Wrapping(I4F4::from_bits(0b11100)));
/// ``` /// ```
/// ///
/// [`F128Bits`]: struct.F128Bits.html
/// [`ToFixed`]: traits/trait.ToFixed.html /// [`ToFixed`]: traits/trait.ToFixed.html
/// [`Wrapping`]: struct.Wrapping.html /// [`Wrapping`]: struct.Wrapping.html
/// [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html /// [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
/// [`f16` feature]: index.html#optional-features
/// [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html /// [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
/// [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html /// [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
/// [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html /// [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
@ -395,13 +394,13 @@ impl<F: Fixed> Wrapping<F> {
/// [`i64`]: https://doc.rust-lang.org/nightly/std/primitive.i64.html /// [`i64`]: https://doc.rust-lang.org/nightly/std/primitive.i64.html
/// [`i8`]: https://doc.rust-lang.org/nightly/std/primitive.i8.html /// [`i8`]: https://doc.rust-lang.org/nightly/std/primitive.i8.html
/// [`isize`]: https://doc.rust-lang.org/nightly/std/primitive.isize.html /// [`isize`]: https://doc.rust-lang.org/nightly/std/primitive.isize.html
/// [`wrapping_to_fixed`]: traits/trait.ToFixed.html#tymethod.wrapping_to_fixed
/// [`u128`]: https://doc.rust-lang.org/nightly/std/primitive.u128.html /// [`u128`]: https://doc.rust-lang.org/nightly/std/primitive.u128.html
/// [`u16`]: https://doc.rust-lang.org/nightly/std/primitive.u16.html /// [`u16`]: https://doc.rust-lang.org/nightly/std/primitive.u16.html
/// [`u32`]: https://doc.rust-lang.org/nightly/std/primitive.u32.html /// [`u32`]: https://doc.rust-lang.org/nightly/std/primitive.u32.html
/// [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html /// [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html
/// [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html /// [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html
/// [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html /// [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
/// [`wrapping_to_fixed`]: traits/trait.ToFixed.html#tymethod.wrapping_to_fixed
/// [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite /// [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
#[inline] #[inline]
pub fn from_num<Src: ToFixed>(src: Src) -> Wrapping<F> { pub fn from_num<Src: ToFixed>(src: Src) -> Wrapping<F> {
@ -419,12 +418,11 @@ impl<F: Fixed> Wrapping<F> {
/// [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or /// [`isize`], [`u8`], [`u16`], [`u32`], [`u64`], [`u128`], or
/// [`usize`]. Any fractional bits are discarded, which rounds /// [`usize`]. Any fractional bits are discarded, which rounds
/// towards −∞. /// towards −∞.
/// * A floating-point number of type [`f32`] or [`f64`]. If the /// * A floating-point number of type [`f16`], [`bf16`],
/// [`f16` feature] is enabled, it can also be of type [`f16`] /// [`f32`], [`f64`] or [`F128Bits`]. For this conversion, the
/// or [`bf16`]. For this conversion, the method rounds to the /// method rounds to the nearest, with ties rounding to even.
/// nearest, with ties rounding to even. /// * Any other type `Dst` for which [`FromFixed`] is
/// * Any other type `Dst` for which [`FromFixed`] is implemented, in /// implemented, in which case this method returns
/// which case this method returns
/// [`Dst::wrapping_from_fixed(self.0)`][`wrapping_from_fixed`]. /// [`Dst::wrapping_from_fixed(self.0)`][`wrapping_from_fixed`].
/// ///
/// # Examples /// # Examples
@ -446,13 +444,12 @@ impl<F: Fixed> Wrapping<F> {
/// assert_eq!(src.to_num::<I2F6>(), wrapped); /// assert_eq!(src.to_num::<I2F6>(), wrapped);
/// ``` /// ```
/// ///
/// [`F128Bits`]: struct.F128Bits.html
/// [`FromFixed`]: traits/trait.FromFixed.html /// [`FromFixed`]: traits/trait.FromFixed.html
/// [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html /// [`bf16`]: https://docs.rs/half/^1.2/half/struct.bf16.html
/// [`f16` feature]: index.html#optional-features
/// [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html /// [`f16`]: https://docs.rs/half/^1.2/half/struct.f16.html
/// [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html /// [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
/// [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html /// [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
/// [`wrapping_from_fixed`]: traits/trait.FromFixed.html#tymethod.wrapping_from_fixed
/// [`i128`]: https://doc.rust-lang.org/nightly/std/primitive.i128.html /// [`i128`]: https://doc.rust-lang.org/nightly/std/primitive.i128.html
/// [`i16`]: https://doc.rust-lang.org/nightly/std/primitive.i16.html /// [`i16`]: https://doc.rust-lang.org/nightly/std/primitive.i16.html
/// [`i32`]: https://doc.rust-lang.org/nightly/std/primitive.i32.html /// [`i32`]: https://doc.rust-lang.org/nightly/std/primitive.i32.html
@ -465,6 +462,7 @@ impl<F: Fixed> Wrapping<F> {
/// [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html /// [`u64`]: https://doc.rust-lang.org/nightly/std/primitive.u64.html
/// [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html /// [`u8`]: https://doc.rust-lang.org/nightly/std/primitive.u8.html
/// [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html /// [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
/// [`wrapping_from_fixed`]: traits/trait.FromFixed.html#tymethod.wrapping_from_fixed
#[inline] #[inline]
pub fn to_num<Dst: FromFixed>(self) -> Dst { pub fn to_num<Dst: FromFixed>(self) -> Dst {
Dst::wrapping_from_fixed(self.0) Dst::wrapping_from_fixed(self.0)