+ check argument range for cosh/sinh

This commit is contained in:
florian 2024-09-04 22:08:45 +02:00
parent cd13d5bb3a
commit d4a2f67a6d

View File

@ -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);