Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -5739,24 +5739,56 @@ int_round(int argc, VALUE* argv, VALUE num)
}

/*
* :markup: markdown
*
* call-seq:
* floor(ndigits = 0) -> integer
*
* Returns the largest number less than or equal to +self+ with
* a precision of +ndigits+ decimal digits.
* Returns an integer that is a "floor" value for `self`,
* as specified by the given `ndigits`,
* which must be an
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me, but minor nit: the linebreaks on this line look unnecessarily short.

Copy link
Member Author

Choose a reason for hiding this comment

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

As an old-time documentor, I've found that future edits (and the diffs thereof) go better if each clause has its own line; that's why I broke after each of the two commas. The link is on its own line (l. 5750) because it's 90+ characters long by itself.

* [integer-convertible object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
*
* When +ndigits+ is negative, the returned value
* has at least <tt>ndigits.abs</tt> trailing zeros:
* - When `self` is zero, returns zero (regardless of the value of `ndigits`):
*
* 555.floor(-1) # => 550
* 555.floor(-2) # => 500
* -555.floor(-2) # => -600
* 555.floor(-3) # => 0
* ```
* 0.floor(2) # => 0
* 0.floor(-2) # => 0
* ```
*
* Returns +self+ when +ndigits+ is zero or positive.
* - When `self` is non-zero and `ndigits` is non-negative, returns `self`:
*
* ```
* 555.floor # => 555
* 555.floor(50) # => 555
* ```
*
* - When `self` is non-zero and `ndigits` is negative,
* returns a value based on a computed granularity:
*
* - The granularity is <tt>ndigits.abs * 10</tt>.
* - The returned value is the largest multiple of the granularity
* that is less than or equal to `self`.
*
* Examples with positive `self`:
*
* | ndigits | Granularity | 1234.floor(ndigits) |
* |--------:|------------:|--------------------:|
* | -1 | 10 | 1230 |
* | -2 | 100 | 1200 |
* | -3 | 1000 | 1000 |
* | -4 | 10000 | 0 |
* | -5 | 100000 | 0 |
*
* Examples with negative `self`:
*
* 555.floor # => 555
* 555.floor(50) # => 555
* | ndigits | Granularity | -1234.floor(ndigits) |
* |--------:|------------:|---------------------:|
* | -1 | 10 | -1240 |
* | -2 | 100 | -1300 |
* | -3 | 1000 | -2000 |
* | -4 | 10000 | -10000 |
* | -5 | 100000 | -100000 |
*
* Related: Integer#ceil.
*
Expand Down