@@ -5695,24 +5695,56 @@ int_round(int argc, VALUE* argv, VALUE num)
5695
5695
}
5696
5696
5697
5697
/*
5698
+ * :markup: markdown
5699
+ *
5698
5700
* call-seq:
5699
5701
* floor(ndigits = 0) -> integer
5700
5702
*
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).
5703
5707
*
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`):
5706
5709
*
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
+ * ```
5711
5714
*
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`:
5713
5740
*
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 |
5716
5748
*
5717
5749
* Related: Integer#ceil.
5718
5750
*
0 commit comments