[前][次][番号順一覧][スレッド一覧]

ruby-changes:46178

From: stomar <ko1@a...>
Date: Sun, 9 Apr 2017 22:30:37 +0900 (JST)
Subject: [ruby-changes:46178] stomar:r58291 (trunk): math.c: improve docs for Math.sqrt

stomar	2017-04-09 22:30:31 +0900 (Sun, 09 Apr 2017)

  New Revision: 58291

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58291

  Log:
    math.c: improve docs for Math.sqrt
    
    * math.c: [DOC] mention possibly surprising behavior of Math.sqrt
      due to floating point arithmetic; also refer to BigDecimal#sqrt.

  Modified files:
    trunk/math.c
Index: math.c
===================================================================
--- math.c	(revision 58290)
+++ math.c	(revision 58291)
@@ -590,6 +590,13 @@ math_log10(VALUE unused_obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L590
  *    #   [8, 2.82842712474619, 8.0]
  *    #   [9, 3.0, 9.0]
  *    #   [10, 3.16227766016838, 10.0]
+ *
+ *  Note that the limited precision of floating point arithmetic
+ *  might lead to surprising results:
+ *
+ *    Math.sqrt(10**46).to_i  #=> 99999999999999991611392 (!)
+ *
+ *  See also BigDecimal#sqrt.
  */
 
 static VALUE

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]