Răsfoiți Sursa

* math.hypot(): factor larger argument out of expression in order to avoid loss of precision.

git-svn-id: trunk@26026 -
sergei 11 ani în urmă
părinte
comite
437b3755d1
1 a modificat fișierele cu 8 adăugiri și 1 ștergeri
  1. 8 1
      rtl/objpas/math.pp

+ 8 - 1
rtl/objpas/math.pp

@@ -844,7 +844,14 @@ function artanh(x : float) : float;
 
 function hypot(x,y : float) : float;
   begin
-     hypot:=Sqrt(x*x+y*y)
+    x:=abs(x);
+    y:=abs(y);
+    if (x>y) then
+      hypot:=x*sqrt(1.0+sqr(y/x))
+    else if (x>0.0) then
+      hypot:=y*sqrt(1.0+sqr(x/y))
+    else
+      hypot:=y;
   end;
 
 function log10(x : float) : float;