docs: change wording from truncate to discard fractional bits
Truncation might be interpreted to mean rounding towards zero, which is not what happens in negative two's-complement fixed-point numbers. So "extra fractional bits are truncated" is better as "extra fractional bits are discarded, which rounds towards −∞."
This commit is contained in:
parent
1eca782f60
commit
13010d6ed9
|
@ -146,7 +146,7 @@ macro_rules! convert_lossy {
|
||||||
/// This conversion never fails (infallible) but may lose
|
/// This conversion never fails (infallible) but may lose
|
||||||
/// precision (lossy). Any fractional bits in the source
|
/// precision (lossy). Any fractional bits in the source
|
||||||
/// that cannot be represented in the destination are
|
/// that cannot be represented in the destination are
|
||||||
/// truncated.
|
/// discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn lossy_from(src: $SrcU<FracSrc>) -> Self {
|
fn lossy_from(src: $SrcU<FracSrc>) -> Self {
|
||||||
src.to_num()
|
src.to_num()
|
||||||
|
@ -165,7 +165,7 @@ macro_rules! convert_lossy {
|
||||||
/// This conversion never fails (infallible) but may lose
|
/// This conversion never fails (infallible) but may lose
|
||||||
/// precision (lossy). Any fractional bits in the source
|
/// precision (lossy). Any fractional bits in the source
|
||||||
/// that cannot be represented in the destination are
|
/// that cannot be represented in the destination are
|
||||||
/// truncated.
|
/// discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn lossy_from(src: $SrcI<FracSrc>) -> Self {
|
fn lossy_from(src: $SrcI<FracSrc>) -> Self {
|
||||||
src.to_num()
|
src.to_num()
|
||||||
|
@ -184,7 +184,7 @@ macro_rules! convert_lossy {
|
||||||
/// This conversion never fails (infallible) but may lose
|
/// This conversion never fails (infallible) but may lose
|
||||||
/// precision (lossy). Any fractional bits in the source
|
/// precision (lossy). Any fractional bits in the source
|
||||||
/// that cannot be represented in the destination are
|
/// that cannot be represented in the destination are
|
||||||
/// truncated.
|
/// discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn lossy_from(src: $SrcU<FracSrc>) -> Self {
|
fn lossy_from(src: $SrcU<FracSrc>) -> Self {
|
||||||
src.to_num()
|
src.to_num()
|
||||||
|
@ -618,7 +618,7 @@ macro_rules! fixed_to_int_lossy {
|
||||||
///
|
///
|
||||||
/// This conversion never fails (infallible) but may lose
|
/// This conversion never fails (infallible) but may lose
|
||||||
/// precision (lossy). Any fractional bits in the source
|
/// precision (lossy). Any fractional bits in the source
|
||||||
/// are truncated.
|
/// are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn lossy_from(src: $SrcU<FracSrc>) -> Self {
|
fn lossy_from(src: $SrcU<FracSrc>) -> Self {
|
||||||
src.to_num()
|
src.to_num()
|
||||||
|
@ -634,7 +634,7 @@ macro_rules! fixed_to_int_lossy {
|
||||||
///
|
///
|
||||||
/// This conversion never fails (infallible) but may lose
|
/// This conversion never fails (infallible) but may lose
|
||||||
/// precision (lossy). Any fractional bits in the source
|
/// precision (lossy). Any fractional bits in the source
|
||||||
/// are truncated.
|
/// are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn lossy_from(src: $SrcI<FracSrc>) -> Self {
|
fn lossy_from(src: $SrcI<FracSrc>) -> Self {
|
||||||
src.to_num()
|
src.to_num()
|
||||||
|
@ -650,7 +650,7 @@ macro_rules! fixed_to_int_lossy {
|
||||||
///
|
///
|
||||||
/// This conversion never fails (infallible) but may lose
|
/// This conversion never fails (infallible) but may lose
|
||||||
/// precision (lossy). Any fractional bits in the source
|
/// precision (lossy). Any fractional bits in the source
|
||||||
/// are truncated.
|
/// are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn lossy_from(src: $SrcU<FracSrc>) -> Self {
|
fn lossy_from(src: $SrcU<FracSrc>) -> Self {
|
||||||
src.to_num()
|
src.to_num()
|
||||||
|
|
|
@ -20,7 +20,8 @@ macro_rules! fixed_from_to {
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`].
|
||||||
|
@ -102,10 +103,12 @@ assert_eq!(Fix::from_num(",
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`]. Any fractional bits are truncated.
|
[`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 [`f32`] or [`f64`]. If the [`f16`
|
||||||
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
||||||
For this conversion, the method rounds to the nearest, with ties
|
For this conversion, the method rounds to the nearest, with ties
|
||||||
|
@ -189,7 +192,8 @@ fits, otherwise returns [`None`].
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`].
|
||||||
|
@ -276,10 +280,12 @@ fits, otherwise returns [`None`].
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`]. Any fractional bits are truncated.
|
[`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 [`f32`] or [`f64`]. If the [`f16`
|
||||||
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
||||||
For this conversion, the method rounds to the nearest, with ties
|
For this conversion, the method rounds to the nearest, with ties
|
||||||
|
@ -362,7 +368,8 @@ saturating if it does not fit.
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`].
|
||||||
|
@ -456,10 +463,12 @@ saturating the value if it does not fit.
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`]. Any fractional bits are truncated.
|
[`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 [`f32`] or [`f64`]. If the [`f16`
|
||||||
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
||||||
For this conversion, the method rounds to the nearest, with ties
|
For this conversion, the method rounds to the nearest, with ties
|
||||||
|
@ -543,7 +552,8 @@ wrapping the value on overflow.
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`].
|
||||||
|
@ -623,10 +633,12 @@ wrapping the value on overflow.
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`]. Any fractional bits are truncated.
|
[`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 [`f32`] or [`f64`]. If the [`f16`
|
||||||
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
||||||
For this conversion, the method rounds to the nearest, with ties
|
For this conversion, the method rounds to the nearest, with ties
|
||||||
|
@ -713,7 +725,8 @@ returned.
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`].
|
||||||
|
@ -799,10 +812,12 @@ overflow has occurred. On overflow, the wrapped value is returned.
|
||||||
|
|
||||||
The other number can be:
|
The other number can be:
|
||||||
|
|
||||||
* Another fixed-point number. Any extra fractional bits are truncated.
|
* Another fixed-point number. Any extra fractional bits are
|
||||||
|
discarded, which rounds towards −∞.
|
||||||
* 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`]. Any fractional bits are truncated.
|
[`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 [`f32`] or [`f64`]. If the [`f16`
|
||||||
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
feature] is enabled, it can also be of type [`f16`] or [`bf16`].
|
||||||
For this conversion, the method rounds to the nearest, with ties
|
For this conversion, the method rounds to the nearest, with ties
|
||||||
|
|
|
@ -1363,7 +1363,7 @@ where
|
||||||
pub trait FromFixed {
|
pub trait FromFixed {
|
||||||
/// Converts from a fixed-point number.
|
/// Converts from a fixed-point number.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
|
@ -1378,7 +1378,7 @@ pub trait FromFixed {
|
||||||
|
|
||||||
/// Converts from a fixed-point number if it fits, otherwise returns [`None`].
|
/// Converts from a fixed-point number if it fits, otherwise returns [`None`].
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`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
|
||||||
fn checked_from_fixed<F: Fixed>(src: F) -> Option<Self>
|
fn checked_from_fixed<F: Fixed>(src: F) -> Option<Self>
|
||||||
|
@ -1387,12 +1387,12 @@ pub trait FromFixed {
|
||||||
|
|
||||||
/// Converts from a fixed-point number, saturating if it does not fit.
|
/// Converts from a fixed-point number, saturating if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
fn saturating_from_fixed<F: Fixed>(src: F) -> Self;
|
fn saturating_from_fixed<F: Fixed>(src: F) -> Self;
|
||||||
|
|
||||||
/// Converts from a fixed-point number, wrapping if it does not fit.
|
/// Converts from a fixed-point number, wrapping if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
fn wrapping_from_fixed<F: Fixed>(src: F) -> Self;
|
fn wrapping_from_fixed<F: Fixed>(src: F) -> Self;
|
||||||
|
|
||||||
/// Converts from a fixed-point number.
|
/// Converts from a fixed-point number.
|
||||||
|
@ -1401,7 +1401,7 @@ pub trait FromFixed {
|
||||||
/// an overflow has occurred. On overflow, the wrapped value is
|
/// an overflow has occurred. On overflow, the wrapped value is
|
||||||
/// returned.
|
/// returned.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
||||||
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
|
@ -1436,7 +1436,7 @@ pub trait FromFixed {
|
||||||
pub trait ToFixed {
|
pub trait ToFixed {
|
||||||
/// Converts to a fixed-point number.
|
/// Converts to a fixed-point number.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
|
@ -1454,14 +1454,14 @@ pub trait ToFixed {
|
||||||
|
|
||||||
/// Converts to a fixed-point number if it fits, otherwise returns [`None`].
|
/// Converts to a fixed-point number if it fits, otherwise returns [`None`].
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`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
|
||||||
fn checked_to_fixed<F: Fixed>(self) -> Option<F>;
|
fn checked_to_fixed<F: Fixed>(self) -> Option<F>;
|
||||||
|
|
||||||
/// Converts to a fixed-point number, saturating if it does not fit.
|
/// Converts to a fixed-point number, saturating if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
|
@ -1472,7 +1472,7 @@ pub trait ToFixed {
|
||||||
|
|
||||||
/// Converts to a fixed-point number, wrapping if it does not fit.
|
/// Converts to a fixed-point number, wrapping if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
|
@ -1487,7 +1487,7 @@ pub trait ToFixed {
|
||||||
/// indicating whether an overflow has occurred. On overflow, the
|
/// indicating whether an overflow has occurred. On overflow, the
|
||||||
/// wrapped value is returned.
|
/// wrapped value is returned.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
|
@ -1561,7 +1561,7 @@ macro_rules! impl_int {
|
||||||
impl FromFixed for $Int {
|
impl FromFixed for $Int {
|
||||||
/// Converts a fixed-point number to an integer.
|
/// Converts a fixed-point number to an integer.
|
||||||
///
|
///
|
||||||
/// Any fractional bits are truncated.
|
/// Any fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
|
@ -1580,7 +1580,7 @@ macro_rules! impl_int {
|
||||||
|
|
||||||
/// Converts a fixed-point number to an integer if it fits, otherwise returns [`None`].
|
/// Converts a fixed-point number to an integer if it fits, otherwise returns [`None`].
|
||||||
///
|
///
|
||||||
/// Any fractional bits are truncated.
|
/// Any fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`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
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1590,7 +1590,7 @@ macro_rules! impl_int {
|
||||||
|
|
||||||
/// Converts a fixed-point number to an integer, saturating if it does not fit.
|
/// Converts a fixed-point number to an integer, saturating if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any fractional bits are truncated.
|
/// Any fractional bits are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_from_fixed<F: Fixed>(src: F) -> Self {
|
fn saturating_from_fixed<F: Fixed>(src: F) -> Self {
|
||||||
$Int::from_repr_fixed(FromFixed::saturating_from_fixed(src))
|
$Int::from_repr_fixed(FromFixed::saturating_from_fixed(src))
|
||||||
|
@ -1598,7 +1598,7 @@ macro_rules! impl_int {
|
||||||
|
|
||||||
/// Converts a fixed-point number to an integer, wrapping if it does not fit.
|
/// Converts a fixed-point number to an integer, wrapping if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any fractional bits are truncated.
|
/// Any fractional bits are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_from_fixed<F: Fixed>(src: F) -> Self {
|
fn wrapping_from_fixed<F: Fixed>(src: F) -> Self {
|
||||||
$Int::from_repr_fixed(FromFixed::wrapping_from_fixed(src))
|
$Int::from_repr_fixed(FromFixed::wrapping_from_fixed(src))
|
||||||
|
@ -1610,7 +1610,7 @@ macro_rules! impl_int {
|
||||||
/// an overflow has occurred. On overflow, the wrapped value is
|
/// an overflow has occurred. On overflow, the wrapped value is
|
||||||
/// returned.
|
/// returned.
|
||||||
///
|
///
|
||||||
/// Any fractional bits are truncated.
|
/// Any fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
||||||
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
|
@ -2064,7 +2064,7 @@ macro_rules! impl_fixed {
|
||||||
impl<Frac: $LeEqU> FromFixed for $Fixed<Frac> {
|
impl<Frac: $LeEqU> FromFixed for $Fixed<Frac> {
|
||||||
/// Converts a fixed-point number.
|
/// Converts a fixed-point number.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed<F: Fixed>(src: F) -> Self {
|
fn from_fixed<F: Fixed>(src: F) -> Self {
|
||||||
let (wrapped, overflow) = FromFixed::overflowing_from_fixed(src);
|
let (wrapped, overflow) = FromFixed::overflowing_from_fixed(src);
|
||||||
|
@ -2075,7 +2075,7 @@ macro_rules! impl_fixed {
|
||||||
|
|
||||||
/// Converts a fixed-point number if it fits, otherwise returns [`None`].
|
/// Converts a fixed-point number if it fits, otherwise returns [`None`].
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`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
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2088,7 +2088,7 @@ macro_rules! impl_fixed {
|
||||||
|
|
||||||
/// Converts a fixed-point number, saturating if it does not fit.
|
/// Converts a fixed-point number, saturating if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_from_fixed<F: Fixed>(src: F) -> Self {
|
fn saturating_from_fixed<F: Fixed>(src: F) -> Self {
|
||||||
let conv = src.private_to_fixed_helper(Self::FRAC_NBITS, Self::INT_NBITS);
|
let conv = src.private_to_fixed_helper(Self::FRAC_NBITS, Self::INT_NBITS);
|
||||||
|
@ -2118,7 +2118,7 @@ macro_rules! impl_fixed {
|
||||||
|
|
||||||
/// Converts a fixed-point number, wrapping if it does not fit.
|
/// Converts a fixed-point number, wrapping if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_from_fixed<F: Fixed>(src: F) -> Self {
|
fn wrapping_from_fixed<F: Fixed>(src: F) -> Self {
|
||||||
let (wrapped, _) = FromFixed::overflowing_from_fixed(src);
|
let (wrapped, _) = FromFixed::overflowing_from_fixed(src);
|
||||||
|
@ -2131,7 +2131,7 @@ macro_rules! impl_fixed {
|
||||||
/// indicating whether an overflow has occurred. On
|
/// indicating whether an overflow has occurred. On
|
||||||
/// overflow, the wrapped value is returned.
|
/// overflow, the wrapped value is returned.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
||||||
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
|
@ -2165,7 +2165,7 @@ macro_rules! impl_fixed {
|
||||||
impl<Frac: $LeEqU> ToFixed for $Fixed<Frac> {
|
impl<Frac: $LeEqU> ToFixed for $Fixed<Frac> {
|
||||||
/// Converts a fixed-point number.
|
/// Converts a fixed-point number.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_fixed<F: Fixed>(self) -> F {
|
fn to_fixed<F: Fixed>(self) -> F {
|
||||||
FromFixed::from_fixed(self)
|
FromFixed::from_fixed(self)
|
||||||
|
@ -2173,7 +2173,7 @@ macro_rules! impl_fixed {
|
||||||
|
|
||||||
/// Converts a fixed-point number if it fits, otherwise returns [`None`].
|
/// Converts a fixed-point number if it fits, otherwise returns [`None`].
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`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
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2183,7 +2183,7 @@ macro_rules! impl_fixed {
|
||||||
|
|
||||||
/// Converts a fixed-point number, saturating if it does not fit.
|
/// Converts a fixed-point number, saturating if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_to_fixed<F: Fixed>(self) -> F {
|
fn saturating_to_fixed<F: Fixed>(self) -> F {
|
||||||
FromFixed::saturating_from_fixed(self)
|
FromFixed::saturating_from_fixed(self)
|
||||||
|
@ -2191,7 +2191,7 @@ macro_rules! impl_fixed {
|
||||||
|
|
||||||
/// Converts a fixed-point number, wrapping if it does not fit.
|
/// Converts a fixed-point number, wrapping if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_to_fixed<F: Fixed>(self) -> F {
|
fn wrapping_to_fixed<F: Fixed>(self) -> F {
|
||||||
FromFixed::wrapping_from_fixed(self)
|
FromFixed::wrapping_from_fixed(self)
|
||||||
|
@ -2203,7 +2203,7 @@ macro_rules! impl_fixed {
|
||||||
/// indicating whether an overflow has occurred. On
|
/// indicating whether an overflow has occurred. On
|
||||||
/// overflow, the wrapped value is returned.
|
/// overflow, the wrapped value is returned.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are discarded, which rounds towards −∞.
|
||||||
///
|
///
|
||||||
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
||||||
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
|
|
|
@ -124,7 +124,8 @@ impl<F: Fixed> Wrapping<F> {
|
||||||
///
|
///
|
||||||
/// The other number can be:
|
/// The other number can be:
|
||||||
///
|
///
|
||||||
/// * A fixed-point number. Any extra fractional bits are truncated.
|
/// * A fixed-point number. Any extra fractional bits are
|
||||||
|
/// discarded, which rounds towards −∞.
|
||||||
/// * 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`].
|
||||||
|
@ -195,10 +196,12 @@ impl<F: Fixed> Wrapping<F> {
|
||||||
///
|
///
|
||||||
/// The other number can be:
|
/// The other number can be:
|
||||||
///
|
///
|
||||||
/// * Another fixed-point number. Any extra fractional bits are truncated.
|
/// * Another fixed-point number. Any extra fractional bits are
|
||||||
|
/// discarded, which rounds towards −∞.
|
||||||
/// * 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`]. Any fractional bits are truncated.
|
/// [`usize`]. Any fractional bits are discarded, which rounds
|
||||||
|
/// towards −∞.
|
||||||
/// * A floating-point number of type [`f32`] or [`f64`]. If the
|
/// * A floating-point number of type [`f32`] or [`f64`]. If the
|
||||||
/// [`f16` feature] is enabled, it can also be of type [`f16`]
|
/// [`f16` feature] is enabled, it can also be of type [`f16`]
|
||||||
/// or [`bf16`]. For this conversion, the method rounds to the
|
/// or [`bf16`]. For this conversion, the method rounds to the
|
||||||
|
|
Loading…
Reference in New Issue