[DOC] Doc for Float#ceil (#11125)

This commit is contained in:
Burdette Lamar 2024-07-09 08:43:07 -05:00 committed by GitHub
parent ab3fa8dece
commit 30b9912bb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2213,36 +2213,78 @@ flo_floor(int argc, VALUE *argv, VALUE num)
} }
/* /*
* :markup: markdown
*
* call-seq: * call-seq:
* ceil(ndigits = 0) -> float or integer * ceil(ndigits = 0) -> float or integer
* *
* Returns the smallest number greater than or equal to +self+ with * Returns a numeric that is a "ceiling" value for `self`,
* a precision of +ndigits+ decimal digits. * as specified by the given `ndigits`,
* which must be an
* [integer-convertible object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
* *
* When +ndigits+ is positive, returns a float with +ndigits+ * When `ndigits` is positive, returns a Float with `ndigits`
* digits after the decimal point (as available): * decimal digits after the decimal point
* (as available, but no fewer than 1):
* *
* ```
* f = 12345.6789 * f = 12345.6789
* f.ceil(1) # => 12345.7 * f.ceil(1) # => 12345.7
* f.ceil(3) # => 12345.679 * f.ceil(3) # => 12345.679
* f.ceil(30) # => 12345.6789
* f = -12345.6789 * f = -12345.6789
* f.ceil(1) # => -12345.6 * f.ceil(1) # => -12345.6
* f.ceil(3) # => -12345.678 * f.ceil(3) # => -12345.678
* f.ceil(30) # => -12345.6789
* f = 0.0
* f.ceil(1) # => 0.0
* f.ceil(100) # => 0.0
* ```
* *
* When +ndigits+ is non-positive, returns an integer with at least * When `ndigits` is non-positive,
* <code>ndigits.abs</code> trailing zeros: * returns an Integer based on a computed granularity:
* *
* f = 12345.6789 * - The granularity is `10 ** ndigits.abs`.
* f.ceil(0) # => 12346 * - The returned value is the largest multiple of the granularity
* f.ceil(-3) # => 13000 * that is less than or equal to `self`.
* f = -12345.6789 *
* f.ceil(0) # => -12345 * Examples with positive `self`:
* f.ceil(-3) # => -12000 *
* | ndigits | Granularity | 12345.6789.ceil(ndigits) |
* |--------:|------------:|-------------------------:|
* | 0 | 1 | 12346 |
* | -1 | 10 | 12350 |
* | -2 | 100 | 12400 |
* | -3 | 1000 | 13000 |
* | -4 | 10000 | 20000 |
* | -5 | 100000 | 100000 |
*
* Examples with negative `self`:
*
* | ndigits | Granularity | -12345.6789.ceil(ndigits) |
* |--------:|------------:|--------------------------:|
* | 0 | 1 | -12345 |
* | -1 | 10 | -12340 |
* | -2 | 100 | -12300 |
* | -3 | 1000 | -12000 |
* | -4 | 10000 | -10000 |
* | -5 | 100000 | 0 |
*
* When `self` is zero and `ndigits` is non-positive,
* returns Integer zero:
*
* ```
* 0.0.ceil(0) # => 0
* 0.0.ceil(-1) # => 0
* 0.0.ceil(-2) # => 0
* ```
* *
* Note that the limited precision of floating-point arithmetic * Note that the limited precision of floating-point arithmetic
* may lead to surprising results: * may lead to surprising results:
* *
* (2.1 / 0.7).ceil #=> 4 (!) * ```
* (2.1 / 0.7).ceil #=> 4 # Not 3 (because 2.1 / 0.7 # => 3.0000000000000004, not 3.0)
* ```
* *
* Related: Float#floor. * Related: Float#floor.
* *