From 7ee977f9f3011157d5a26d0ce15af5b8e54be22a Mon Sep 17 00:00:00 2001
From: Simon Praetorius <simon.praetorius@tu-dresden.de>
Date: Tue, 25 May 2010 15:56:13 +0000
Subject: [PATCH] Phi*ToR(): rounding-errors will be attended, because the
 domain of atanh is (-1,1)

---
 AMDiS/src/MathFunctions.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/AMDiS/src/MathFunctions.h b/AMDiS/src/MathFunctions.h
index 356bfa20..3daba46b 100644
--- a/AMDiS/src/MathFunctions.h
+++ b/AMDiS/src/MathFunctions.h
@@ -16,8 +16,12 @@ namespace AMDiS {
   }
 
   //convert Phi1 to r
-  inline double Phi1ToR(double p1, double eps) { return atanh(1-2*p1)*eps/3; }
+  inline double Phi1ToR(double p1, double eps) {
+	return eps/3.0 * atanh( std::max(-1+1.e-14, std::min(1-1.e-14, 1-2*p1)) );
+  }
   //convert Phi2 to r
-  inline double Phi2ToR(double p2, double eps) { return atanh(1+2*p2)*eps/3; }
+  inline double Phi2ToR(double p2, double eps) {
+	return eps/3.0 * atanh( std::max(-1+1.e-14, std::min(1-1.e-14, 1+2*p2) );
+  }
 }
 #endif
-- 
GitLab