Skip to content

Commit f5dfadf

Browse files
[DOC] Doc for Integer#floor (#11077)
1 parent b974c84 commit f5dfadf

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

numeric.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5695,24 +5695,56 @@ int_round(int argc, VALUE* argv, VALUE num)
56955695
}
56965696

56975697
/*
5698+
* :markup: markdown
5699+
*
56985700
* call-seq:
56995701
* floor(ndigits = 0) -> integer
57005702
*
5701-
* Returns the largest number less than or equal to +self+ with
5702-
* a precision of +ndigits+ decimal digits.
5703+
* Returns an integer that is a "floor" value for `self`,
5704+
* as specified by the given `ndigits`,
5705+
* which must be an
5706+
* [integer-convertible object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
57035707
*
5704-
* When +ndigits+ is negative, the returned value
5705-
* has at least <tt>ndigits.abs</tt> trailing zeros:
5708+
* - When `self` is zero, returns zero (regardless of the value of `ndigits`):
57065709
*
5707-
* 555.floor(-1) # => 550
5708-
* 555.floor(-2) # => 500
5709-
* -555.floor(-2) # => -600
5710-
* 555.floor(-3) # => 0
5710+
* ```
5711+
* 0.floor(2) # => 0
5712+
* 0.floor(-2) # => 0
5713+
* ```
57115714
*
5712-
* Returns +self+ when +ndigits+ is zero or positive.
5715+
* - When `self` is non-zero and `ndigits` is non-negative, returns `self`:
5716+
*
5717+
* ```
5718+
* 555.floor # => 555
5719+
* 555.floor(50) # => 555
5720+
* ```
5721+
*
5722+
* - When `self` is non-zero and `ndigits` is negative,
5723+
* returns a value based on a computed granularity:
5724+
*
5725+
* - The granularity is <tt>ndigits.abs * 10</tt>.
5726+
* - The returned value is the largest multiple of the granularity
5727+
* that is less than or equal to `self`.
5728+
*
5729+
* Examples with positive `self`:
5730+
*
5731+
* | ndigits | Granularity | 1234.floor(ndigits) |
5732+
* |--------:|------------:|--------------------:|
5733+
* | -1 | 10 | 1230 |
5734+
* | -2 | 100 | 1200 |
5735+
* | -3 | 1000 | 1000 |
5736+
* | -4 | 10000 | 0 |
5737+
* | -5 | 100000 | 0 |
5738+
*
5739+
* Examples with negative `self`:
57135740
*
5714-
* 555.floor # => 555
5715-
* 555.floor(50) # => 555
5741+
* | ndigits | Granularity | -1234.floor(ndigits) |
5742+
* |--------:|------------:|---------------------:|
5743+
* | -1 | 10 | -1240 |
5744+
* | -2 | 100 | -1300 |
5745+
* | -3 | 1000 | -2000 |
5746+
* | -4 | 10000 | -10000 |
5747+
* | -5 | 100000 | -100000 |
57165748
*
57175749
* Related: Integer#ceil.
57185750
*

0 commit comments

Comments
 (0)