Skip to content

Commit

Permalink
Rollup merge of rust-lang#58812 - jonhoo:floor_v_trunc, r=alexcrichton
Browse files Browse the repository at this point in the history
Clarify distinction between floor() and trunc()

`floor()` rounds towards `-INF`, `trunc()` rounds towards 0.
This PR clarifies this in the examples.
  • Loading branch information
Centril committed Mar 19, 2019
2 parents fff8586 + c5fe405 commit 5abd9c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ impl f32 {
/// # Examples
///
/// ```
/// let f = 3.99_f32;
/// let f = 3.7_f32;
/// let g = 3.0_f32;
/// let h = -3.7_f32;
///
/// assert_eq!(f.floor(), 3.0);
/// assert_eq!(g.floor(), 3.0);
/// assert_eq!(h.floor(), -4.0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -104,11 +106,13 @@ impl f32 {
/// # Examples
///
/// ```
/// let f = 3.3_f32;
/// let g = -3.7_f32;
/// let f = 3.7_f32;
/// let g = 3.0_f32;
/// let h = -3.7_f32;
///
/// assert_eq!(f.trunc(), 3.0);
/// assert_eq!(g.trunc(), -3.0);
/// assert_eq!(g.trunc(), 3.0);
/// assert_eq!(h.trunc(), -3.0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down
12 changes: 8 additions & 4 deletions src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ impl f64 {
/// # Examples
///
/// ```
/// let f = 3.99_f64;
/// let f = 3.7_f64;
/// let g = 3.0_f64;
/// let h = -3.7_f64;
///
/// assert_eq!(f.floor(), 3.0);
/// assert_eq!(g.floor(), 3.0);
/// assert_eq!(h.floor(), -4.0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -84,11 +86,13 @@ impl f64 {
/// # Examples
///
/// ```
/// let f = 3.3_f64;
/// let g = -3.7_f64;
/// let f = 3.7_f64;
/// let g = 3.0_f64;
/// let h = -3.7_f64;
///
/// assert_eq!(f.trunc(), 3.0);
/// assert_eq!(g.trunc(), -3.0);
/// assert_eq!(g.trunc(), 3.0);
/// assert_eq!(h.trunc(), -3.0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down

0 comments on commit 5abd9c7

Please sign in to comment.