Browse Source

* attempt to fix overflow handling in hyperbolic harmonic functions better, still not there I think

florian 1 month ago
parent
commit
a8953e0832
1 changed files with 18 additions and 4 deletions
  1. 18 4
      rtl/objpas/math.pp

+ 18 - 4
rtl/objpas/math.pp

@@ -1290,11 +1290,13 @@ function cosh(x : Single) : Single;
   var
   var
      temp : ValReal;
      temp : ValReal;
   begin
   begin
+     if (x>8.94159862326326216608E+0001) or (x<-8.94159862326326216608E+0001) then
 {$push}
 {$push}
 {$checkfpuexceptions on}
 {$checkfpuexceptions on}
-     if (x>8.94159862326326216608E+0001) or (x<-8.94159862326326216608E+0001) then
        exit(huge_single*huge_single);
        exit(huge_single*huge_single);
+{$pop}
     temp:=exp(x);
     temp:=exp(x);
+{$push}
 {$safefpuexceptions on}
 {$safefpuexceptions on}
      cosh:=0.5*(temp+1.0/temp);
      cosh:=0.5*(temp+1.0/temp);
 {$pop}
 {$pop}
@@ -1307,11 +1309,13 @@ function cosh(x : Double) : Double;
   var
   var
      temp : ValReal;
      temp : ValReal;
   begin
   begin
+     if (x>7.10475860073943942030E+0002) or (x<-7.10475860073943942030E+0002) then
 {$push}
 {$push}
 {$checkfpuexceptions on}
 {$checkfpuexceptions on}
-     if (x>7.10475860073943942030E+0002) or (x<-7.10475860073943942030E+0002) then
        exit(huge_double*huge_double);
        exit(huge_double*huge_double);
+{$pop}
      temp:=exp(x);
      temp:=exp(x);
+{$push}
 {$safefpuexceptions on}
 {$safefpuexceptions on}
      cosh:=0.5*(temp+1.0/temp);
      cosh:=0.5*(temp+1.0/temp);
 {$pop}
 {$pop}
@@ -1335,16 +1339,21 @@ function sinh(x : Single) : Single;
   var
   var
      temp : ValReal;
      temp : ValReal;
   begin
   begin
+     if x>8.94159862326326216608E+0001 then
 {$push}
 {$push}
 {$checkfpuexceptions on}
 {$checkfpuexceptions on}
-     if x>8.94159862326326216608E+0001 then
        exit(huge_single*huge_single);
        exit(huge_single*huge_single);
+{$pop}
      if x<-8.94159862326326216608E+0001 then
      if x<-8.94159862326326216608E+0001 then
+{$push}
+{$checkfpuexceptions on}
        exit(-(huge_single*huge_single));
        exit(-(huge_single*huge_single));
+{$pop}
      temp:=exp(x);
      temp:=exp(x);
      { gives better behavior around zero, and in particular ensures that sinh(-0.0)=-0.0 }
      { gives better behavior around zero, and in particular ensures that sinh(-0.0)=-0.0 }
      if temp=1 then
      if temp=1 then
        exit(x);
        exit(x);
+{$push}
 {$safefpuexceptions on}
 {$safefpuexceptions on}
      sinh:=0.5*(temp-1.0/temp);
      sinh:=0.5*(temp-1.0/temp);
 {$pop}
 {$pop}
@@ -1357,15 +1366,20 @@ function sinh(x : Double) : Double;
   var
   var
      temp : ValReal;
      temp : ValReal;
   begin
   begin
+     if x>7.10475860073943942030E+0002 then
 {$push}
 {$push}
 {$checkfpuexceptions on}
 {$checkfpuexceptions on}
-     if x>7.10475860073943942030E+0002 then
        exit(huge_double*huge_double);
        exit(huge_double*huge_double);
+{$pop}
      if x<-7.10475860073943942030E+0002 then
      if x<-7.10475860073943942030E+0002 then
+{$push}
+{$checkfpuexceptions on}
        exit(-(huge_double*huge_double));
        exit(-(huge_double*huge_double));
+{$pop}
      temp:=exp(x);
      temp:=exp(x);
      if temp=1 then
      if temp=1 then
        exit(x);
        exit(x);
+{$push}
 {$safefpuexceptions on}
 {$safefpuexceptions on}
      sinh:=0.5*(temp-1.0/temp);
      sinh:=0.5*(temp-1.0/temp);
 {$pop}
 {$pop}