Skip to content

Commit 9930647

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
Doc for Integer#ceil
1 parent 3e14fe7 commit 9930647

File tree

1 file changed

+47
-12
lines changed

1 file changed

+47
-12
lines changed

numeric.c

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5776,27 +5776,62 @@ int_floor(int argc, VALUE* argv, VALUE num)
57765776
}
57775777

57785778
/*
5779+
* :markup: markdown
5780+
*
57795781
* call-seq:
57805782
* ceil(ndigits = 0) -> integer
57815783
*
5782-
* Returns the smallest number greater than or equal to +self+ with
5783-
* a precision of +ndigits+ decimal digits.
5784+
* Returns an integer that is a "ceiling" value for `self`,
5785+
* as specified by the given `ndigits`,
5786+
* which must be an
5787+
* [integer-convertible object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
57845788
*
5785-
* When the precision is negative, the returned value is an integer
5786-
* with at least <code>ndigits.abs</code> trailing zeros:
5789+
* - When `self` is zero, returns zero (regardless of the value of `ndigits`):
57875790
*
5788-
* 555.ceil(-1) # => 560
5789-
* 555.ceil(-2) # => 600
5790-
* -555.ceil(-2) # => -500
5791-
* 555.ceil(-3) # => 1000
5791+
* ```
5792+
* 0.ceil(2) # => 0
5793+
* 0.ceil(-2) # => 0
5794+
* ```
57925795
*
5793-
* Returns +self+ when +ndigits+ is zero or positive.
5796+
* - When `self` is non-zero and `ndigits` is non-negative, returns `self`:
57945797
*
5795-
* 555.ceil # => 555
5796-
* 555.ceil(50) # => 555
5798+
* ```
5799+
* 555.ceil # => 555
5800+
* 555.ceil(50) # => 555
5801+
* ```
57975802
*
5798-
* Related: Integer#floor.
5803+
* - When `self` is non-zero and `ndigits` is negative,
5804+
* returns a value based on a computed granularity:
5805+
*
5806+
* - The granularity is <tt>ndigits.abs * 10</tt>.
5807+
* - The returned value is the smallest multiple of the granularity
5808+
* that is greater than or equal to `self`.
5809+
*
5810+
* Examples with positive `self`:
57995811
*
5812+
* | ndigits | Granularity | 1234.ceil(ndigits) |
5813+
* |--------:|------------:|-------------------:|
5814+
* | -1 | 10 | 1240 |
5815+
* | -2 | 100 | 1300 |
5816+
* | -3 | 1000 | 2000 |
5817+
* | -4 | 10000 | 10000 |
5818+
* | -5 | 100000 | 100000 |
5819+
*
5820+
* <br>
5821+
*
5822+
* Examples with negative `self`:
5823+
*
5824+
* | ndigits | Granularity | -1234.ceil(ndigits) |
5825+
* |--------:|------------:|--------------------:|
5826+
* | -1 | 10 | -1230 |
5827+
* | -2 | 100 | -1200 |
5828+
* | -3 | 1000 | -1000 |
5829+
* | -4 | 10000 | 0 |
5830+
* | -5 | 100000 | 0 |
5831+
*
5832+
* <br>
5833+
*
5834+
* Related: Integer#floor.
58005835
*/
58015836

58025837
static VALUE

0 commit comments

Comments
 (0)