Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Improve formatting and cross-linking. #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cast.rs
Expand Up @@ -102,15 +102,15 @@ pub trait ToPrimitive {
}

/// Converts the value of `self` to an `f32`. Overflows may map to positive
/// or negative inifinity, otherwise `None` is returned if the value cannot
/// or negative infinity, otherwise `None` is returned if the value cannot
/// be represented by an `f32`.
#[inline]
fn to_f32(&self) -> Option<f32> {
self.to_f64().as_ref().and_then(ToPrimitive::to_f32)
}

/// Converts the value of `self` to an `f64`. Overflows may map to positive
/// or negative inifinity, otherwise `None` is returned if the value cannot
/// or negative infinity, otherwise `None` is returned if the value cannot
/// be represented by an `f64`.
///
/// The default implementation tries to convert through `to_i64()`, and
Expand Down
28 changes: 14 additions & 14 deletions src/float.rs
Expand Up @@ -8,7 +8,7 @@ use crate::{Num, NumCast, ToPrimitive};

/// Generic trait for floating point numbers that works with `no_std`.
///
/// This trait implements a subset of the `Float` trait.
/// This trait implements a subset of the [`Float`] trait.
pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
/// Returns positive infinity.
///
Expand Down Expand Up @@ -267,9 +267,9 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
self.classify() == FpCategory::Subnormal
}

/// Returns the floating point category of the number. If only one property
/// is going to be tested, it is generally faster to use the specific
/// predicate instead.
/// Returns the [floating point category](FpCategory) of the number. If
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the links you added on FloatCore, could you do the same on Float?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing! Will get to it over the weekend, hopefully.

/// only one property is going to be tested, it is generally faster to
/// use the specific predicate instead.
///
/// # Examples
///
Expand Down Expand Up @@ -463,8 +463,8 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
}
}

/// Computes the absolute value of `self`. Returns `FloatCore::nan()` if the
/// number is `FloatCore::nan()`.
/// Computes the absolute value of `self`. Returns [`FloatCore::nan()`] if the
/// number is [`FloatCore::nan()`].
///
/// # Examples
///
Expand Down Expand Up @@ -496,9 +496,9 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {

/// Returns a number that represents the sign of `self`.
///
/// - `1.0` if the number is positive, `+0.0` or `FloatCore::infinity()`
/// - `-1.0` if the number is negative, `-0.0` or `FloatCore::neg_infinity()`
/// - `FloatCore::nan()` if the number is `FloatCore::nan()`
/// - `1.0` if the number is positive, `+0.0` or [`FloatCore::infinity()`]
/// - `-1.0` if the number is negative, `-0.0` or [`FloatCore::neg_infinity()`]
/// - [`FloatCore::nan()`] if the number is [`FloatCore::nan()`]
///
/// # Examples
///
Expand Down Expand Up @@ -529,7 +529,7 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
}

/// Returns `true` if `self` is positive, including `+0.0` and
/// `FloatCore::infinity()`, and `FloatCore::nan()`.
/// [`FloatCore::infinity()`], and [`FloatCore::nan()`].
///
/// # Examples
///
Expand All @@ -556,7 +556,7 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
}

/// Returns `true` if `self` is negative, including `-0.0` and
/// `FloatCore::neg_infinity()`, and `-FloatCore::nan()`.
/// [`FloatCore::neg_infinity()`], and [`-FloatCore::nan()`](FloatCore::nan).
///
/// # Examples
///
Expand Down Expand Up @@ -676,7 +676,7 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {

/// Raise a number to an integer power.
///
/// Using this function is generally faster than using `powf`
/// Using this function is generally faster than using `powf`.
///
/// # Examples
///
Expand Down Expand Up @@ -1010,7 +1010,7 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ```
fn max_value() -> Self;

/// Returns `true` if this value is `NaN` and false otherwise.
/// Returns `true` if this value is `NaN` and `false` otherwise.
///
/// ```
/// use num_traits::Float;
Expand All @@ -1025,7 +1025,7 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
fn is_nan(self) -> bool;

/// Returns `true` if this value is positive infinity or negative infinity and
/// false otherwise.
/// `false` otherwise.
///
/// ```
/// use num_traits::Float;
Expand Down
14 changes: 7 additions & 7 deletions src/int.rs
Expand Up @@ -16,9 +16,9 @@ use crate::{Num, NumCast};
/// and behave like builtin integers. Furthermore, the types are expected to expose the integer
/// value in binary representation and support bitwise operators. The standard bitwise operations
/// (e.g., bitwise-and, bitwise-or, right-shift, left-shift) are inherited and the trait extends
/// these with introspective queries (e.g., `PrimInt::count_ones()`, `PrimInt::leading_zeros()`),
/// bitwise combinators (e.g., `PrimInt::rotate_left()`), and endianness converters (e.g.,
/// `PrimInt::to_be()`).
/// these with introspective queries (e.g., [`PrimInt::count_ones()`], [`PrimInt::leading_zeros()`]),
/// bitwise combinators (e.g., [`PrimInt::rotate_left()`]), and endianness converters (e.g.,
/// [`PrimInt::to_be()`]).
///
/// All `PrimInt` types are expected to be fixed-width binary integers. The width can be queried
/// via `T::zero().count_zeros()`. The trait currently lacks a way to query the width at
Expand Down Expand Up @@ -171,7 +171,7 @@ pub trait PrimInt:
/// Shifts the bits to the left by a specified amount, `n`, filling
/// zeros in the least significant bits.
///
/// This is bitwise equivalent to signed `Shl`.
/// This is bitwise equivalent to signed [`Shl`].
///
/// # Examples
///
Expand All @@ -188,7 +188,7 @@ pub trait PrimInt:
/// Shifts the bits to the right by a specified amount, `n`, copying
/// the "sign bit" in the most significant bits even for unsigned types.
///
/// This is bitwise equivalent to signed `Shr`.
/// This is bitwise equivalent to signed [`Shr`].
///
/// # Examples
///
Expand All @@ -205,7 +205,7 @@ pub trait PrimInt:
/// Shifts the bits to the left by a specified amount, `n`, filling
/// zeros in the least significant bits.
///
/// This is bitwise equivalent to unsigned `Shl`.
/// This is bitwise equivalent to unsigned [`Shl`].
///
/// # Examples
///
Expand All @@ -222,7 +222,7 @@ pub trait PrimInt:
/// Shifts the bits to the right by a specified amount, `n`, filling
/// zeros in the most significant bits.
///
/// This is bitwise equivalent to unsigned `Shr`.
/// This is bitwise equivalent to unsigned [`Shr`].
///
/// # Examples
///
Expand Down
17 changes: 9 additions & 8 deletions src/real.rs
Expand Up @@ -135,8 +135,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ```
fn fract(self) -> Self;

/// Computes the absolute value of `self`. Returns `Float::nan()` if the
/// number is `Float::nan()`.
/// Computes the absolute value of `self`. Returns [`Float::nan()`] if the
/// number is [`Float::nan()`].
///
/// ```
/// use num_traits::real::Real;
Expand All @@ -157,9 +157,9 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {

/// Returns a number that represents the sign of `self`.
///
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
/// - `Float::nan()` if the number is `Float::nan()`
/// - `1.0` if the number is positive, `+0.0` or [`Float::infinity()`]
/// - `-1.0` if the number is negative, `-0.0` or [`Float::neg_infinity()`]
/// - `Float::nan()` if the number is [`Float::nan()`]
///
/// ```
/// use num_traits::real::Real;
Expand All @@ -175,7 +175,7 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
fn signum(self) -> Self;

/// Returns `true` if `self` is positive, including `+0.0`,
/// `Float::infinity()`, and with newer versions of Rust `f64::NAN`.
/// [`Float::infinity()`], and with newer versions of Rust [`f64::NAN`].
///
/// ```
/// use num_traits::real::Real;
Expand All @@ -193,7 +193,7 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
fn is_sign_positive(self) -> bool;

/// Returns `true` if `self` is negative, including `-0.0`,
/// `Float::neg_infinity()`, and with newer versions of Rust `-f64::NAN`.
/// [`Float::neg_infinity()`], and with newer versions of Rust [`-f64::NAN`](f64::NAN).
///
/// ```
/// use num_traits::real::Real;
Expand Down Expand Up @@ -244,7 +244,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {

/// Raise a number to an integer power.
///
/// Using this function is generally faster than using `powf`
/// Using this function is generally faster than using
/// [`powf`](Self::powf())
///
/// ```
/// use num_traits::real::Real;
Expand Down
4 changes: 2 additions & 2 deletions src/sign.rs
Expand Up @@ -34,10 +34,10 @@ pub trait Signed: Sized + Num + Neg<Output = Self> {
/// * `-1` if the number is negative
fn signum(&self) -> Self;

/// Returns true if the number is positive and false if the number is zero or negative.
/// Returns `true` if the number is positive and `false` if the number is zero or negative.
fn is_positive(&self) -> bool;

/// Returns true if the number is negative and false if the number is zero or positive.
/// Returns `true` if the number is negative and `false` if the number is zero or positive.
fn is_negative(&self) -> bool;
}

Expand Down