docs: link to F::is_{finite,nan} in impl {To,From}Fixed for F
Before this commit, all links were to the f64 documentation, even for implementations for f32, f16 and bf16.
This commit is contained in:
parent
f86e59a204
commit
8803e0786d
124
src/traits.rs
124
src/traits.rs
|
@ -1510,7 +1510,7 @@ impl_int! { u128 }
|
||||||
impl_int! { usize }
|
impl_int! { usize }
|
||||||
|
|
||||||
macro_rules! impl_float {
|
macro_rules! impl_float {
|
||||||
($Float:ty) => {
|
($Float:ty, $link:expr) => {
|
||||||
impl FromFixed for $Float {
|
impl FromFixed for $Float {
|
||||||
/// Converts a fixed-point number to a floating-point number.
|
/// Converts a fixed-point number to a floating-point number.
|
||||||
///
|
///
|
||||||
|
@ -1578,23 +1578,23 @@ macro_rules! impl_float {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToFixed for $Float {
|
impl ToFixed for $Float {
|
||||||
/// Converts a floating-point number to a fixed-point number.
|
comment! {
|
||||||
///
|
"Converts a floating-point number to a fixed-point number.
|
||||||
/// Rounding is to the nearest, with ties rounded to even.
|
|
||||||
///
|
Rounding is to the nearest, with ties rounded to even.
|
||||||
/// # Panics
|
|
||||||
///
|
# Panics
|
||||||
/// Panics if `self` is not [finite].
|
|
||||||
///
|
Panics if `self` is not [finite].
|
||||||
/// When debug assertions are enabled, also panics if the
|
|
||||||
/// value does not fit. When debug assertions are not
|
When debug assertions are enabled, also panics if the value does not
|
||||||
/// enabled, the wrapped value can be returned, but it is
|
fit. When debug assertions are not enabled, the wrapped value can be
|
||||||
/// not considered a breaking change if in the future it
|
returned, but it is not considered a breaking change if in the future
|
||||||
/// panics; if wrapping is required use
|
it panics; if wrapping is required use [`wrapping_to_fixed`] instead.
|
||||||
/// [`wrapping_to_fixed`] instead.
|
|
||||||
///
|
[`wrapping_to_fixed`]: #method.wrapping_to_fixed
|
||||||
/// [`wrapping_to_fixed`]: #method.wrapping_to_fixed
|
[finite]: ", $link, "#method.is_finite
|
||||||
/// [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_fixed<F: Fixed>(self) -> F {
|
fn to_fixed<F: Fixed>(self) -> F {
|
||||||
let (wrapped, overflow) = ToFixed::overflowing_to_fixed(self);
|
let (wrapped, overflow) = ToFixed::overflowing_to_fixed(self);
|
||||||
|
@ -1602,6 +1602,7 @@ macro_rules! impl_float {
|
||||||
let _ = overflow;
|
let _ = overflow;
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts a floating-point number to a fixed-point
|
/// Converts a floating-point number to a fixed-point
|
||||||
/// number if it fits, otherwise returns [`None`].
|
/// number if it fits, otherwise returns [`None`].
|
||||||
|
@ -1624,54 +1625,62 @@ macro_rules! impl_float {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a floating-point number to a fixed-point
|
comment! {
|
||||||
/// number, saturating if it does not fit.
|
"Converts a floating-point number to a fixed-point
|
||||||
///
|
number, saturating if it does not fit.
|
||||||
/// Rounding is to the nearest, with ties rounded to even.
|
|
||||||
///
|
Rounding is to the nearest, with ties rounded to even.
|
||||||
/// # Panics
|
|
||||||
///
|
# Panics
|
||||||
/// Panics if `self` is [NaN].
|
|
||||||
///
|
Panics if `self` is [NaN].
|
||||||
/// [NaN]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_nan
|
|
||||||
|
[NaN]: ", $link, "#method.is_nan
|
||||||
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_to_fixed<F: Fixed>(self) -> F {
|
fn saturating_to_fixed<F: Fixed>(self) -> F {
|
||||||
let kind = self.to_float_kind(F::frac_nbits(), F::int_nbits());
|
let kind = self.to_float_kind(F::frac_nbits(), F::int_nbits());
|
||||||
let helper = FromFloatHelper { kind };
|
let helper = FromFloatHelper { kind };
|
||||||
F::private_saturating_from_float_helper(helper)
|
F::private_saturating_from_float_helper(helper)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts a floating-point number to a fixed-point
|
comment! {
|
||||||
/// number, wrapping if it does not fit.
|
"Converts a floating-point number to a fixed-point
|
||||||
///
|
number, wrapping if it does not fit.
|
||||||
/// Rounding is to the nearest, with ties rounded to even.
|
|
||||||
///
|
Rounding is to the nearest, with ties rounded to even.
|
||||||
/// # Panics
|
|
||||||
///
|
# Panics
|
||||||
/// Panics if `self` is not [finite].
|
|
||||||
///
|
Panics if `self` is not [finite].
|
||||||
/// [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
|
|
||||||
|
[finite]: ", $link, "#method.is_finite
|
||||||
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_to_fixed<F: Fixed>(self) -> F {
|
fn wrapping_to_fixed<F: Fixed>(self) -> F {
|
||||||
let (wrapped, _) = ToFixed::overflowing_to_fixed(self);
|
let (wrapped, _) = ToFixed::overflowing_to_fixed(self);
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts a floating-point number to a fixed-point number.
|
comment! {
|
||||||
///
|
"Converts a floating-point number to a fixed-point number.
|
||||||
/// Returns a [tuple] of the fixed-point number and a [`bool`]
|
|
||||||
/// indicating whether an overflow has occurred. On overflow, the
|
Returns a [tuple] of the fixed-point number and a [`bool`] indicating
|
||||||
/// wrapped value is returned.
|
whether an overflow has occurred. On overflow, the wrapped value is
|
||||||
///
|
returned.
|
||||||
/// Rounding is to the nearest, with ties rounded to even.
|
|
||||||
///
|
Rounding is to the nearest, with ties rounded to even.
|
||||||
/// # Panics
|
|
||||||
///
|
# Panics
|
||||||
/// Panics if `self` is not [finite].
|
|
||||||
///
|
Panics if `self` is not [finite].
|
||||||
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
|
||||||
/// [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
|
[`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
||||||
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
[finite]: ", $link, "#method.is_finite
|
||||||
|
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_to_fixed<F: Fixed>(self) -> (F, bool) {
|
fn overflowing_to_fixed<F: Fixed>(self) -> (F, bool) {
|
||||||
let kind = self.to_float_kind(F::frac_nbits(), F::int_nbits());
|
let kind = self.to_float_kind(F::frac_nbits(), F::int_nbits());
|
||||||
|
@ -1679,15 +1688,16 @@ macro_rules! impl_float {
|
||||||
F::private_overflowing_from_float_helper(helper)
|
F::private_overflowing_from_float_helper(helper)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "f16")]
|
#[cfg(feature = "f16")]
|
||||||
impl_float! { f16 }
|
impl_float! { f16, "https://docs.rs/half/^1/half/struct.f16.html" }
|
||||||
#[cfg(feature = "f16")]
|
#[cfg(feature = "f16")]
|
||||||
impl_float! { bf16 }
|
impl_float! { bf16, "https://docs.rs/half/^1/half/struct.bf16.html" }
|
||||||
impl_float! { f32 }
|
impl_float! { f32, "https://doc.rust-lang.org/nightly/std/primitive.f32.html" }
|
||||||
impl_float! { f64 }
|
impl_float! { f64, "https://doc.rust-lang.org/nightly/std/primitive.f64.html" }
|
||||||
|
|
||||||
macro_rules! trait_delegate {
|
macro_rules! trait_delegate {
|
||||||
(fn $method:ident($($param:ident: $Param:ty),*) -> $Ret:ty) => {
|
(fn $method:ident($($param:ident: $Param:ty),*) -> $Ret:ty) => {
|
||||||
|
|
Loading…
Reference in New Issue