aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authorstomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-09 13:28:11 +0000
committerstomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-09 13:28:11 +0000
commit1c1790d86c6a30479015ce4c6e482db3db4183d7 (patch)
treec11a16473dad61def7c03968e0e27077585bd2e0 /numeric.c
parentb5abd2efb834240413fc0eedbc09e5d5bc844d0b (diff)
downloadruby-1c1790d86c6a30479015ce4c6e482db3db4183d7.tar.gz
numeric.c: improve docs for Float
* numeric.c: [DOC] mention possibly surprising behavior of Float#{floor,ceil,to_i,truncate} due to floating point arithmetic. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index cad2953c8d..f8f0766940 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1964,6 +1964,11 @@ flo_prev_float(VALUE vx)
* 34567.89.floor(1) #=> 34567.8
* 34567.89.floor(2) #=> 34567.89
* 34567.89.floor(3) #=> 34567.89
+ *
+ * Note that the limited precision of floating point arithmetic
+ * might lead to surprising results:
+ *
+ * (0.3 / 0.1).floor #=> 2 (!)
*/
static VALUE
@@ -2026,6 +2031,11 @@ flo_floor(int argc, VALUE *argv, VALUE num)
* 34567.89.ceil(1) #=> 34567.9
* 34567.89.ceil(2) #=> 34567.89
* 34567.89.ceil(3) #=> 34567.89
+ *
+ * Note that the limited precision of floating point arithmetic
+ * might lead to surprising results:
+ *
+ * (2.1 / 0.7).ceil #=> 4 (!)
*/
static VALUE
@@ -2342,6 +2352,11 @@ float_invariant_round(double number, int ndigits, VALUE *num)
* Returns the +float+ truncated to an Integer.
*
* Synonyms are #to_i and #to_int
+ *
+ * Note that the limited precision of floating point arithmetic
+ * might lead to surprising results:
+ *
+ * (0.3 / 0.1).to_i #=> 2 (!)
*/
static VALUE
@@ -2377,6 +2392,11 @@ flo_to_i(VALUE num)
* (-2.8).truncate #=> -2
* 1.234567.truncate(2) #=> 1.23
* 34567.89.truncate(-2) #=> 34500
+ *
+ * Note that the limited precision of floating point arithmetic
+ * might lead to surprising results:
+ *
+ * (0.3 / 0.1).truncate #=> 2 (!)
*/
static VALUE
flo_truncate(int argc, VALUE *argv, VALUE num)