summaryrefslogtreecommitdiffstats
path: root/mathfuncs_rcp.h
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-04-22 23:15:46 -0400
committerErik Schnetter <schnetter@gmail.com>2013-04-22 23:15:46 -0400
commitaa91edeee4d418e72b5aa5e2ffe91b734cc3b73d (patch)
tree408d9bebc4a911eaf3b67572cc0dfa70703aa177 /mathfuncs_rcp.h
parentac59645aa5aface11f713026e2f2c6ac72fc0250 (diff)
downloadvecmathlib-aa91edeee4d418e72b5aa5e2ffe91b734cc3b73d.zip
vecmathlib-aa91edeee4d418e72b5aa5e2ffe91b734cc3b73d.tar.gz
Improve rcp accuracy
Diffstat (limited to 'mathfuncs_rcp.h')
-rw-r--r--mathfuncs_rcp.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/mathfuncs_rcp.h b/mathfuncs_rcp.h
index 81f77ea..586e9d1 100644
--- a/mathfuncs_rcp.h
+++ b/mathfuncs_rcp.h
@@ -33,8 +33,12 @@ namespace vecmathlib {
// Solve f(r) = 0 for f(r) = x - 1/r
// r <- r - f(r) / f'(r)
// r <- 2 r - r^2 x
- r *= RV(2.0) - r * x;
- }
+ // r <- r + r (1 - r x)
+
+ // Note: don't rewrite this expression, this may introduce
+ // cancellation errors
+ r += r * (RV(1.0) - x*r);
+ }
// Handle negative values
r = copysign(r, x0);
OpenPOWER on IntegriCloud