aboutsummaryrefslogtreecommitdiffstats
path: root/math.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-06 14:01:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-06 14:01:43 +0000
commitc067c295a9c78506409704360538c65678022b70 (patch)
treef73f0aee5ae6ff2b100f76df7f2049014bf2bf98 /math.c
parent9d0441696aabc7fc5ab3ecf01c3783e16db079e8 (diff)
downloadruby-c067c295a9c78506409704360538c65678022b70.tar.gz
math.c: adjust cbrt
* math.c (math_cbrt): refine the approximation result on boundary values by an iteration of Newton-Raphson method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/math.c b/math.c
index 0b15ba7056..509cd46ef2 100644
--- a/math.c
+++ b/math.c
@@ -689,7 +689,14 @@ rb_math_sqrt(VALUE x)
static VALUE
math_cbrt(VALUE unused_obj, VALUE x)
{
- return DBL2NUM(cbrt(Get_Double(x)));
+ double f = Get_Double(x);
+ double r = cbrt(f);
+#if defined __GLIBC__
+ if (isfinite(r)) {
+ r = (2.0 * r + (f / r / r)) / 3.0;
+ }
+#endif
+ return DBL2NUM(r);
}
/*