Skip to content

Commit 3d5a3bd

Browse files
Rollup merge of #156392 - Wilfred:float_ceil_docs, r=Mark-Simulacrum
Improve doc comments for f32::ceil() and f32::floor() Previously ::floor() included an example showing behaviour for negative values, but ::ceil() did not. Ensure both have examples of the negative case, for both f32 and f64. Whilst we're here, tweak the wording slightly so it reads better.
2 parents 420f230 + e8eb80b commit 3d5a3bd

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

library/std/src/num/f32.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::sys::cmath;
2626

2727
#[cfg(not(test))]
2828
impl f32 {
29-
/// Returns the largest integer less than or equal to `self`.
29+
/// Returns the largest integer that is less than or equal to `self`.
3030
///
3131
/// This function always returns the precise result.
3232
///
@@ -50,7 +50,7 @@ impl f32 {
5050
core::f32::math::floor(self)
5151
}
5252

53-
/// Returns the smallest integer greater than or equal to `self`.
53+
/// Returns the smallest integer that is greater than or equal to `self`.
5454
///
5555
/// This function always returns the precise result.
5656
///
@@ -59,9 +59,11 @@ impl f32 {
5959
/// ```
6060
/// let f = 3.01_f32;
6161
/// let g = 4.0_f32;
62+
/// let h = -3.01_f32;
6263
///
6364
/// assert_eq!(f.ceil(), 4.0);
6465
/// assert_eq!(g.ceil(), 4.0);
66+
/// assert_eq!(h.ceil(), -3.0);
6567
/// ```
6668
#[doc(alias = "ceiling")]
6769
#[rustc_allow_incoherent_impl]

library/std/src/num/f64.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::sys::cmath;
2626

2727
#[cfg(not(test))]
2828
impl f64 {
29-
/// Returns the largest integer less than or equal to `self`.
29+
/// Returns the largest integer that is less than or equal to `self`.
3030
///
3131
/// This function always returns the precise result.
3232
///
@@ -50,7 +50,7 @@ impl f64 {
5050
core::f64::math::floor(self)
5151
}
5252

53-
/// Returns the smallest integer greater than or equal to `self`.
53+
/// Returns the smallest integer that is greater than or equal to `self`.
5454
///
5555
/// This function always returns the precise result.
5656
///
@@ -59,9 +59,11 @@ impl f64 {
5959
/// ```
6060
/// let f = 3.01_f64;
6161
/// let g = 4.0_f64;
62+
/// let h = -3.01_f64;
6263
///
6364
/// assert_eq!(f.ceil(), 4.0);
6465
/// assert_eq!(g.ceil(), 4.0);
66+
/// assert_eq!(h.ceil(), -3.0);
6567
/// ```
6668
#[doc(alias = "ceiling")]
6769
#[rustc_allow_incoherent_impl]

0 commit comments

Comments
 (0)