Browse Source

+ check argument range for cosh/sinh

florian 11 months ago
parent
commit
d4a2f67a6d
1 changed files with 22 additions and 0 deletions
  1. 22 0
      rtl/objpas/math.pp

+ 22 - 0
rtl/objpas/math.pp

@@ -1263,12 +1263,19 @@ function arctan2(y,x : float) : float;
   end;
 {$endif FPC_MATH_HAS_ARCTAN2}
 
+const
+  huge: double = 1e300;
 
 {$ifdef FPC_HAS_TYPE_SINGLE}
 function cosh(x : Single) : Single;
   var
      temp : ValReal;
   begin
+     if x>8.94159862326326216608E+0001 then
+       begin
+         cosh:=huge+huge;
+         exit;
+       end;
      temp:=exp(x);
 {$push}
 {$safefpuexceptions on}
@@ -1283,6 +1290,11 @@ function cosh(x : Double) : Double;
   var
      temp : ValReal;
   begin
+     if x>7.10475860073943942030E+0002 then
+       begin
+         cosh:=huge+huge;
+         exit;
+       end;
      temp:=exp(x);
 {$push}
 {$safefpuexceptions on}
@@ -1307,6 +1319,11 @@ function sinh(x : Single) : Single;
   var
      temp : ValReal;
   begin
+     if x>8.94159862326326216608E+0001 then
+       begin
+         sinh:=huge+huge;
+         exit;
+       end;
      temp:=exp(x);
      { gives better behavior around zero, and in particular ensures that sinh(-0.0)=-0.0 }
      if temp=1 then
@@ -1324,6 +1341,11 @@ function sinh(x : Double) : Double;
   var
      temp : ValReal;
   begin
+     if x>7.10475860073943942030E+0002 then
+       begin
+         sinh:=huge+huge;
+         exit;
+       end;
      temp:=exp(x);
      if temp=1 then
        exit(x);